נקה מסמך

לפעמים ייתכן שיהיה עליך להסיר מידע שאינו בשימוש או לשכפל כדי להקטין את גודל מסמך הפלט וזמן העיבוד.

בעוד שאתה יכול למצוא ולהסיר נתונים שאינם בשימוש, כגון סגנונות או רשימות, או לשכפל מידע באופן ידני, זה יהיה הרבה יותר נוח לעשות זאת באמצעות תכונות ויכולות שסופקו על ידי Aspose.Words.

הכיתה CleanupOptions מאפשרת לך לציין אפשרויות לניקוי מסמכים. כדי להסיר סגנונות כפולים או רק סגנונות או רשימות שאינם בשימוש מהמסמך, אתה יכול להשתמש בשיטה Cleanup.

הסר מידע שאינו בשימוש ממסמך

אתה יכול להשתמש במאפיינים UnusedStyles ו UnusedBuiltinStyles כדי לזהות ולהסיר סגנונות המסומנים כ “לא בשימוש”.

אתה יכול להשתמש במאפיין UnusedLists כדי לזהות ולהסיר רשימות והגדרות רשימה המסומנות כ “לא בשימוש”.

דוגמת הקוד הבאה מראה כיצד להסיר רק סגנונות שאינם בשימוש ממסמך:

For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C
auto doc = MakeObject<Document>(MyDir + u"Unused styles.docx");
// Combined with the built-in styles, the document now has eight styles.
// A custom style is marked as "used" while there is any text within the document
// formatted in that style. This means that the 4 styles we added are currently unused.
std::cout << (String::Format(u"Count of styles before Cleanup: {0}\n", doc->get_Styles()->get_Count()) +
String::Format(u"Count of lists before Cleanup: {0}", doc->get_Lists()->get_Count()))
<< std::endl;
// Cleans unused styles and lists from the document depending on given CleanupOptions.
auto cleanupOptions = MakeObject<CleanupOptions>();
cleanupOptions->set_UnusedLists(false);
cleanupOptions->set_UnusedStyles(true);
doc->Cleanup(cleanupOptions);
std::cout << (String::Format(u"Count of styles after Cleanup was decreased: {0}\n", doc->get_Styles()->get_Count()) +
String::Format(u"Count of lists after Cleanup is the same: {0}", doc->get_Lists()->get_Count()))
<< std::endl;
doc->Save(ArtifactsDir + u"WorkingWithDocumentOptionsAndSettings.CleanupUnusedStylesAndLists.docx");

הסר מידע כפול ממסמך

אתה יכול גם להשתמש במאפיין DuplicateStyle כדי להחליף את כל הסגנונות הכפולים במקור ולהסיר כפילויות ממסמך.

דוגמת הקוד הבאה מראה כיצד להסיר סגנונות כפולים ממסמך:

For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C
auto doc = MakeObject<Document>(MyDir + u"Document.docx");
// Count of styles before Cleanup.
std::cout << doc->get_Styles()->get_Count() << std::endl;
// Cleans duplicate styles from the document.
auto options = MakeObject<CleanupOptions>();
options->set_DuplicateStyle(true);
doc->Cleanup(options);
// Count of styles after Cleanup was decreased.
std::cout << doc->get_Styles()->get_Count() << std::endl;
doc->Save(ArtifactsDir + u"WorkingWithDocumentOptionsAndSettings.CleanupDuplicateStyle.docx");