Word 문서의 옵션 및 모양 작업
때로는 언어 기본 설정이나 페이지당 줄 수를 설정하는 등 문서의 모양을 변경해야 할 수도 있습니다. Aspose.Words는 문서 표시 방법과 몇 가지 추가 옵션을 제어하는 기능을 제공합니다. 이 문서에서는 그러한 가능성에 대해 설명합니다.
문서 표시 옵션 설정
ViewOptions 클래스를 사용하여 Microsoft Word에 문서가 표시되는 방법을 제어할 수 있습니다. 예를 들어 zoom_percent 속성을 사용하여 문서 확대/축소 값을 설정하거나 view_type 속성을 사용하여 보기 모드를 설정할 수 있습니다.
다음 코드 예제에서는 Microsoft Word에서 문서를 열 때 문서가 50%로 표시되도록 하는 방법을 보여줍니다
# 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") | |
doc.view_options.view_type = aw.settings.ViewType.PAGE_LAYOUT | |
doc.view_options.zoom_percent = 50 | |
doc.save(docs_base.artifacts_dir + "WorkingWithDocumentOptionsAndSettings.view_options.docx") |
페이지 표시 옵션 설정
한 줄당 문자 수를 설정하려면 characters_per_line 속성을 사용하십시오. Word 문서의 페이지당 줄 수를 설정할 수도 있습니다. lines_per_page 속성을 사용하여 문서 격자의 페이지당 줄 수를 가져오거나 설정합니다.
다음 코드 예제에서는 Microsoft Word 문서의 줄당 문자 수와 페이지당 줄 수를 설정하는 방법을 보여줍니다
# 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") | |
# Set the layout mode for a section allowing to define the document grid behavior. | |
# Note that the Document Grid tab becomes visible in the Page Setup dialog of MS Word | |
# if any Asian language is defined as editing language. | |
doc.first_section.page_setup.layout_mode = aw.SectionLayoutMode.GRID | |
doc.first_section.page_setup.characters_per_line = 30 | |
doc.first_section.page_setup.lines_per_page = 10 | |
doc.save(docs_base.artifacts_dir + "WorkingWithDocumentOptionsAndSettings.document_page_setup.docx") |
언어 기본 설정 지정
Microsoft Word에 문서를 표시하는 것은 이 문서의 기본값으로 설정된 언어에 따라 달라집니다. 기본적으로 언어가 설정되지 않은 경우 Microsoft Word는 “Office 언어 기본 설정 지정” 대화 상자에서 정보를 가져옵니다. 예를 들어 Microsoft Word 2019의 “파일 → 옵션 → 언어"에서 찾을 수 있습니다.
Aspose.Words를 사용하면 LanguagePreferences 클래스를 사용하여 언어 기본 설정을 설정할 수도 있습니다. 또한 문서를 올바르게 표시하려면 문서 로드 프로세스와 일치해야 하는 Microsoft Word 버전을 설정해야 합니다. 이는 msw_version 속성을 사용하여 수행할 수 있습니다.
다음 코드 예제에서는 편집 언어에 일본어를 추가하는 방법을 보여줍니다
# For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Python-via-.NET | |
loadOptions = aw.loading.LoadOptions() | |
# Set language preferences that will be used when document is loading. | |
loadOptions.language_preferences.add_editing_language(aw.loading.EditingLanguage.JAPANESE) |
다음 코드 예제에서는 러시아어를 기본 편집 언어로 설정하는 방법을 보여줍니다
# For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Python-via-.NET | |
loadOptions = aw.loading.LoadOptions() | |
loadOptions.language_preferences.default_editing_language = aw.loading.EditingLanguage.RUSSIAN | |
doc = aw.Document(docs_base.my_dir + "No default editing language.docx", loadOptions) | |
localeId = doc.styles.default_font.locale_id | |
print("The document either has no any language set in defaults or it was set to Russian originally." if (localeId == aw.loading.EditingLanguage.RUSSIAN) | |
else "The document default language was set to another than Russian language originally, so it is not overridden.") |
특정 Word 버전에 맞게 문서 최적화
optimize_for 방법을 사용하면 특정 버전의 Microsoft Word에 대한 기본 Aspose.Words 동작뿐만 아니라 문서 콘텐츠를 최적화할 수 있습니다. 이 방법을 사용하면 문서 로드 시 Microsoft Word이 “호환성 모드” 리본을 표시하지 않도록 할 수 있습니다. compliance 속성을 ISO29500_2008_TRANSITIONAL 이상으로 설정해야 할 수도 있습니다.
다음 코드 예제는 Microsoft Word 2016에 맞게 문서 콘텐츠를 최적화하는 방법을 보여줍니다
# 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") | |
doc.compatibility_options.optimize_for(aw.settings.MsWordVersion.WORD2016) | |
doc.save(docs_base.artifacts_dir + "WorkingWithDocumentOptionsAndSettings.optimize_for_ms_word.docx") |