ทำความสะอาดเอกสาร
บางครั้งคุณอาจต้องลบข้อมูลที่ไม่ได้ใช้หรือซ้ำกันเพื่อลดขนาดของเอกสารที่ส่งออกและเว.
ในขณะที่คุณสามารถค้นหาและลบข้อมูลที่ไม่ได้ใช้เช่นลักษณะหรือรายการหรือข้อมูลที่ซ้ำกันด้วยตนเองแต่จะสะดวกกว่ามากในการทำเช่นนี้โดยใช้คุณลักษณะและความสามารถที่มีให้โดย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"); |