Bir Belgeyi Temizle
Bazen, belge boyutunu ve işleme süresini azaltmak için kullanılmayan veya çoğaltılmış bilgileri kaldırmanız gerekebilir.
Kullanılmayan verileri, stil veya listeler gibi bilgileri veya yinelenen bilgileri el ile bulup kaldırabilirsiniz ancak bunları yaparken Aspose.Words tarafından sunulan özellikler ve yetkinlikler ile bunu yapmak çok daha uygun olacaktır.
CleanupOptions sınıfı belgenin temizlenmesi için seçenekler belirtmenizi sağlar. Tekrar eden stilleri ya da sadece kullanılmayan stilleri ya da listeleri belgeyi kaldırmak için, Cleanup yöntemini kullanabilirsiniz.
Bir Belge’den Kullanılmayan Bilgileri Kaldırın
Kullanabileceğiniz " UnusedStyles " ve "" UnusedBuiltinStyles "" özellikleri, “Kullanılmayan” olarak işaretlenmiş stilleri tespit etmek ve kaldırmak için kullanılabilir.
Kullanılabilir UnusedLists özelliğini, “kullanılmayan” olarak işaretlenmiş listeleri ve liste tanımlarını tespit etmek ve kaldırmak için kullanabilirsiniz.
Aşağıdaki kod örneği, bir belgeden kullanılmayan stilleri kaldırmanın nasıl yapılacağını göstermektedir:
// 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"); |
Bir Belge’den Tekrar Eden Bilgileri Kaldır
Ayrıca, tüm yinelenen stilleri orijinal stil ile değiştirmek ve bir belgeden yinelenenler kaldırmak için DuplicateStyle özelliğini kullanabilirsiniz.
Aşağıdaki kod örneği bir belgeden yinelenen stilleri nasıl kaldıracağınızı göstermektedir:
// 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"); |