Bir Belgeyi Temizleme
Bazen çıktı belgesinin boyutunu ve işlem süresini azaltmak için kullanılmayan veya yinelenen bilgileri kaldırmanız gerekebilir.
Stiller veya listeler gibi kullanılmayan verileri bulup kaldırabilirken veya bilgileri manuel olarak çoğaltabilirken, Aspose.Words tarafından sağlanan özellikleri ve yetenekleri kullanarak bunu yapmak çok daha uygun olacaktır.
CleanupOptions sınıfı, belge temizleme seçeneklerini belirlemenizi sağlar. Yinelenen stilleri veya yalnızca kullanılmayan stilleri veya listeleri belgeden kaldırmak için Cleanup yöntemini kullanabilirsiniz.
Kullanılmayan Bilgileri Belgeden Kaldırma
“Kullanılmamış” olarak işaretlenmiş stilleri algılamak ve kaldırmak için UnusedStyles ve UnusedBuiltinStyles özelliklerini kullanabilirsiniz.
“Kullanılmamış” olarak işaretlenmiş listeleri ve liste tanımlarını algılamak ve kaldırmak için UnusedLists özelliğini kullanabilirsiniz.
Aşağıdaki kod örneği, bir belgeden yalnızca kullanılmayan stillerin nasıl kaldırılacağını gösterir:
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"); |
Yinelenen Bilgileri Belgeden Kaldırma
Tüm yinelenen stilleri orijinal stille değiştirmek ve kopyaları bir belgeden kaldırmak için DuplicateStyle özelliğini de kullanabilirsiniz.
Aşağıdaki kod örneği, yinelenen stillerin bir belgeden nasıl kaldırılacağını gösterir:
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"); |