문서 정리
때로는 출력 문서의 크기와 처리 시간을 줄이기 위해 사용되지 않거나 중복된 정보를 제거해야 할 수도 있습니다.
스타일이나 목록 등 사용하지 않는 데이터를 찾아서 제거하거나 정보를 수동으로 복제할 수 있지만 Aspose.Words에서 제공하는 기능을 사용하면 훨씬 더 편리할 것입니다.
CleanupOptions 클래스를 사용하면 문서 정리 옵션을 지정할 수 있습니다. 중복된 스타일을 제거하거나 문서에서 사용되지 않은 스타일이나 목록만 제거하려면 Cleanup 방법을 사용할 수 있습니다.
문서에서 사용하지 않는 정보 제거
UnusedStyles 및 UnusedBuiltinStyles 속성을 사용하여 “사용되지 않음"으로 표시된 스타일을 감지하고 제거할 수 있습니다.
UnusedLists 속성을 사용하여 “사용되지 않음"으로 표시된 목록 및 목록 정의를 감지하고 제거할 수 있습니다.
다음 코드 예제에서는 문서에서 사용되지 않는 스타일만 제거하는 방법을 보여줍니다
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
Document doc = new Document(MyDir + "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. | |
Console.WriteLine($"Count of styles before Cleanup: {doc.Styles.Count}\n" + | |
$"Count of lists before Cleanup: {doc.Lists.Count}"); | |
// Cleans unused styles and lists from the document depending on given CleanupOptions. | |
CleanupOptions cleanupOptions = new CleanupOptions { UnusedLists = false, UnusedStyles = true }; | |
doc.Cleanup(cleanupOptions); | |
Console.WriteLine($"Count of styles after Cleanup was decreased: {doc.Styles.Count}\n" + | |
$"Count of lists after Cleanup is the same: {doc.Lists.Count}"); | |
doc.Save(ArtifactsDir + "WorkingWithDocumentOptionsAndSettings.CleanupUnusedStylesAndLists.docx"); |
문서에서 중복 정보 제거
DuplicateStyle 속성을 사용하여 모든 중복 스타일을 원본 스타일로 대체하고 문서에서 중복을 제거할 수도 있습니다.
다음 코드 예제에서는 문서에서 중복 스타일을 제거하는 방법을 보여줍니다
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
Document doc = new Document(MyDir + "Document.docx"); | |
// Count of styles before Cleanup. | |
Console.WriteLine(doc.Styles.Count); | |
// Cleans duplicate styles from the document. | |
CleanupOptions options = new CleanupOptions { DuplicateStyle = true }; | |
doc.Cleanup(options); | |
// Count of styles after Cleanup was decreased. | |
Console.WriteLine(doc.Styles.Count); | |
doc.Save(ArtifactsDir + "WorkingWithDocumentOptionsAndSettings.CleanupDuplicateStyle.docx"); |