לנקות מסמך

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

בעוד שאתה יכול למצוא ולהסיר נתונים שאינם בשימוש, כגון סגנונות או רשימות, או מידע כפול באופן ידני, זה יהיה הרבה יותר נוח לעשות זאת באמצעות תכונות ויכולות המסופקות על ידי 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-Java
Document doc = new Document(dataDir + "TestFile.doc");
// Count of styles before Cleanup.
System.out.println(doc.getStyles().getCount());
// Count of lists before Cleanup.
System.out.println(doc.getLists().getCount());
CleanupOptions cleanupoptions = new CleanupOptions();
cleanupoptions.setUnusedLists(false);
cleanupoptions.setUnusedStyles(true);
// Cleans unused styles and lists from the document depending on given
// CleanupOptions.
doc.cleanup(cleanupoptions);
// Count of styles after Cleanup was decreased.
System.out.println(doc.getStyles().getCount());
// Count of lists after Cleanup is the same.
System.out.println(doc.getLists().getCount());
doc.save(dataDir + "Document.Cleanup_out.docx");

להסיר מידע מדויק מתעודה

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

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

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java
Document doc = new Document(dataDir + "Document.doc");
// Count of styles before Cleanup.
System.out.println(doc.getStyles().getCount());
CleanupOptions options = new CleanupOptions();
options.setDuplicateStyle(true);
// Cleans duplicate styles from the document.
doc.cleanup(options);
// Count of styles after Cleanup was decreased.
System.out.println(doc.getStyles().getCount());
doc.save(dataDir + "Document.CleanupDuplicateStyle_out.docx");