Vyčistěte dokument
Někdy možná budete muset odstranit nepoužívané nebo duplicitní informace, abyste snížili velikost výstupního dokumentu a dobu zpracování.
I když můžete nepoužívaná data, jako jsou styly nebo seznamy nebo duplicitní informace, najít a odstranit ručně, bude mnohem pohodlnější to provést pomocí funkcí a funkcí poskytovaných Aspose.Words.
Třída CleanupOptions umožňuje zadat možnosti čištění dokumentů. Chcete-li z dokumentu odstranit duplicitní styly nebo pouze nepoužívané styly nebo seznamy, můžete použít metodu Cleanup.
Odebrání nepoužitých informací z dokumentu
Vlastnosti UnusedStyles a UnusedBuiltinStyles můžete použít k detekci a odebrání stylů, které jsou označeny jako"nepoužité".
Vlastnost UnusedLists můžete použít k detekci a odebrání seznamů a definic seznamů, které jsou označeny jako “nepoužité”.
Následující příklad kódu ukazuje, jak z dokumentu odebrat pouze nepoužívané styly:
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"); |
Odstranění duplicitních informací z dokumentu
Vlastnost DuplicateStyle můžete také použít k nahrazení všech duplicitních stylů původním a odstranění duplikátů z dokumentu.
Následující příklad kódu ukazuje, jak odstranit duplicitní styly z dokumentu:
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"); |