문서 정리
경우에 따라 출력 문서의 크기와 처리 시간을 줄이기 위해 사용하지 않거나 중복된 정보를 제거해야 할 수도 있습니다.
스타일이나 목록과 같이 사용하지 않는 데이터를 찾아서 제거하거나 정보를 수동으로 복제 할 수 있지만 다음에서 제공하는 기능과 기능을 사용하여이 작업을 수행하는 것이 훨씬 편리합니다 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"); |