تنظيف وثيقة
في بعض الأحيان قد تحتاج إلى إزالة المعلومات غير المستخدمة أو المكررة لتقليل حجم مستند الإخراج ووقت المعالجة.
بينما يمكنك العثور على البيانات غير المستخدمة وإزالتها، مثل الأنماط أو القوائم، أو تكرار المعلومات يدويا، سيكون من الأنسب القيام بذلك باستخدام الميزات والإمكانيات التي توفرها 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"); |