문서 정리

때로는 출력 문서의 크기와 처리 시간을 줄이기 위해 사용되지 않거나 중복된 정보를 제거해야 할 수도 있습니다.

스타일이나 목록 등 사용하지 않는 데이터를 찾아서 제거하거나 정보를 수동으로 복제할 수 있지만 Aspose.Words에서 제공하는 기능을 사용하면 훨씬 더 편리할 것입니다.

CleanupOptions 클래스를 사용하면 문서 정리 옵션을 지정할 수 있습니다. 중복된 스타일을 제거하거나 문서에서 사용되지 않은 스타일이나 목록만 제거하려면 cleanup 방법을 사용할 수 있습니다.

문서에서 사용하지 않는 정보 제거

unused_stylesunused_builtin_styles 속성을 사용하여 “사용되지 않음"으로 표시된 스타일을 감지하고 제거할 수 있습니다.

unused_lists 속성을 사용하여 “사용되지 않음"으로 표시된 목록 및 목록 정의를 감지하고 제거할 수 있습니다.

다음 코드 예제에서는 문서에서 사용되지 않는 스타일만 제거하는 방법을 보여줍니다

# For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Python-via-.NET
doc = aw.Document(docs_base.my_dir + "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.
print(f"Count of styles before Cleanup: {doc.styles.count}\n" +
f"Count of lists before Cleanup: {doc.lists.count}")
# Cleans unused styles and lists from the document depending on given CleanupOptions.
cleanupOptions = aw.CleanupOptions()
cleanupOptions.unused_lists = False
cleanupOptions.unused_styles = True
doc.cleanup(cleanupOptions)
print(f"Count of styles after Cleanup was decreased: {doc.styles.count}\n" +
f"Count of lists after Cleanup is the same: {doc.lists.count}")
doc.save(docs_base.artifacts_dir + "WorkingWithDocumentOptionsAndSettings.cleanup_unused_styles_and_lists.docx")

문서에서 중복 정보 제거

duplicate_style 속성을 사용하여 모든 중복 스타일을 원본 스타일로 대체하고 문서에서 중복을 제거할 수도 있습니다.

다음 코드 예제에서는 문서에서 중복된 스타일을 제거하는 방법을 보여줍니다

# For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Python-via-.NET
doc = aw.Document(docs_base.my_dir + "Document.docx")
# Count of styles before Cleanup.
print(doc.styles.count)
# Cleans duplicate styles from the document.
options = aw.CleanupOptions()
options.duplicate_style = True
doc.cleanup(options)
# Count of styles after Cleanup was decreased.
print(doc.styles.count)
doc.save(docs_base.artifacts_dir + "WorkingWithDocumentOptionsAndSettings.cleanup_duplicate_style.docx")