לנקות מסמך

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

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

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

הסרת מידע לא משומש ממסמכים

אתה יכול להשתמש UnusedStyles ו UnusedBuiltinStyles תכונות לזהות ולהסיר סגנונות המסומנים כ"לא בשימוש".

אתה יכול להשתמש UnusedLists רכוש כדי לזהות ולהסיר רשימות והגדרות רשימה המסומנים כ"לא בשימוש".

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

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET
Document doc = new Document(MyDir + "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.
Console.WriteLine($"Count of styles before Cleanup: {doc.Styles.Count}\n" +
$"Count of lists before Cleanup: {doc.Lists.Count}");
// Cleans unused styles and lists from the document depending on given CleanupOptions.
CleanupOptions cleanupOptions = new CleanupOptions { UnusedLists = false, UnusedStyles = true };
doc.Cleanup(cleanupOptions);
Console.WriteLine($"Count of styles after Cleanup was decreased: {doc.Styles.Count}\n" +
$"Count of lists after Cleanup is the same: {doc.Lists.Count}");
doc.Save(ArtifactsDir + "WorkingWithDocumentOptionsAndSettings.CleanupUnusedStylesAndLists.docx");

להסיר מידע מדויק ממסמכים

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

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

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET
Document doc = new Document(MyDir + "Document.docx");
// Count of styles before Cleanup.
Console.WriteLine(doc.Styles.Count);
// Cleans duplicate styles from the document.
CleanupOptions options = new CleanupOptions { DuplicateStyle = true };
doc.Cleanup(options);
// Count of styles after Cleanup was decreased.
Console.WriteLine(doc.Styles.Count);
doc.Save(ArtifactsDir + "WorkingWithDocumentOptionsAndSettings.CleanupDuplicateStyle.docx");