문서 정리
경우에 따라 출력 문서의 크기와 처리 시간을 줄이기 위해 사용하지 않거나 중복된 정보를 제거해야 할 수도 있습니다.
스타일이나 목록과 같이 사용하지 않는 데이터를 찾아서 제거하거나 정보를 수동으로 복제 할 수 있지만Aspose.Words에서 제공하는 기능과 기능을 사용하여이 작업을 수행하는 것이 훨씬 편리합니다.
CleanupOptions클래스를 사용하면 문서 정리 옵션을 지정할 수 있습니다. 문서에서 중복 스타일 또는 사용하지 않는 스타일 또는 목록을 제거하려면Cleanup방법을 사용할 수 있습니다.
문서에서 사용하지 않는 정보 제거
UnusedStyles및UnusedBuiltinStyles속성을 사용하여"사용되지 않음"으로 표시된 스타일을 검색 및 제거할 수 있습니다.
UnusedLists속성을 사용하여"사용되지 않음"으로 표시된 목록 및 목록 정의를 검색 및 제거할 수 있습니다.
다음 코드 예제에서는 문서에서 사용하지 않는 스타일만 제거하는 방법을 보여 줍니다:
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java | |
Document doc = new Document(dataDir + "TestFile.doc"); | |
// Count of styles before Cleanup. | |
System.out.println(doc.getStyles().getCount()); | |
// Count of lists before Cleanup. | |
System.out.println(doc.getLists().getCount()); | |
CleanupOptions cleanupoptions = new CleanupOptions(); | |
cleanupoptions.setUnusedLists(false); | |
cleanupoptions.setUnusedStyles(true); | |
// Cleans unused styles and lists from the document depending on given | |
// CleanupOptions. | |
doc.cleanup(cleanupoptions); | |
// Count of styles after Cleanup was decreased. | |
System.out.println(doc.getStyles().getCount()); | |
// Count of lists after Cleanup is the same. | |
System.out.println(doc.getLists().getCount()); | |
doc.save(dataDir + "Document.Cleanup_out.docx"); |
문서에서 중복 정보 제거
DuplicateStyle속성을 사용하여 모든 중복 스타일을 원래 스타일로 대체하고 문서에서 중복을 제거할 수도 있습니다.
다음 코드 예제에서는 문서에서 중복 스타일을 제거하는 방법을 보여 줍니다:
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java | |
Document doc = new Document(dataDir + "Document.doc"); | |
// Count of styles before Cleanup. | |
System.out.println(doc.getStyles().getCount()); | |
CleanupOptions options = new CleanupOptions(); | |
options.setDuplicateStyle(true); | |
// Cleans duplicate styles from the document. | |
doc.cleanup(options); | |
// Count of styles after Cleanup was decreased. | |
System.out.println(doc.getStyles().getCount()); | |
doc.save(dataDir + "Document.CleanupDuplicateStyle_out.docx"); |