پاک کردن یک سند
گاهی اوقات ممکن است لازم باشد اطلاعات استفاده نشده یا تکراری را حذف کنید تا اندازه سند خروجی و زمان پردازش را کاهش دهید.
در حالی که می توانید داده های استفاده نشده مانند سبک ها یا لیست ها یا اطلاعات تکراری را به صورت دستی پیدا و حذف کنید، انجام این کار با استفاده از ویژگی ها و قابلیت های ارائه شده توسط Aspose.Words بسیار راحت تر خواهد بود.
کلاس CleanupOptions به شما اجازه می دهد گزینه هایی برای تمیز کردن اسناد را مشخص کنید. برای حذف سبک های تکراری یا فقط سبک ها یا لیست های استفاده نشده از سند، می توانید از روش Cleanup استفاده کنید.
حذف اطلاعات استفاده نشده از یک سند
شما می توانید از ویژگی های UnusedStyles و UnusedBuiltinStyles برای تشخیص و حذف سبک هایی که به عنوان “استفاده نشده"مشخص شده اند استفاده کنید.
شما می توانید از ویژگی UnusedLists برای شناسایی و حذف لیست ها و تعاریف لیست که به عنوان “استفاده نشده"مشخص شده اند استفاده کنید.
مثال کد زیر نشان می دهد که چگونه فقط سبک های استفاده نشده را از یک سند حذف کنیم:
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"); |
حذف اطلاعات تکراری از یک سند
همچنین می توانید از ویژگی DuplicateStyle برای جایگزینی تمام سبک های تکراری با سبک اصلی و حذف تکراری از یک سند استفاده کنید.
مثال کد زیر نشان می دهد که چگونه سبک های تکراری را از یک سند حذف کنیم:
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"); |