워드 문서의 옵션 및 모양 작업

때로는 문서의 모양을 변경해야 할 수도 있습니다(예:언어 기본 설정 또는 페이지 당 줄 수 설정).Aspose.Words 문서 표시 방법과 몇 가지 추가 옵션을 제어하는 기능을 제공합니다. 이 기사에서는 이러한 가능성을 설명합니다.

문서 표시 옵션 설정

문서 표시 방법을 제어할 수 있습니다 Microsoft Word 를 사용하여 ViewOptions 수업 예를 들어 다음을 사용하여 문서 확대/축소 값을 설정할 수 있습니다 ZoomPercent 속성 또는 뷰 모드를 사용하여 ViewType 재산.

다음 코드 예제에서는 문서를 열 때 50%로 표시되도록 하는 방법을 보여 줍니다 Microsoft Word:

For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C
// The path to the documents directories.
System::String inputDataDir = GetInputDataDir_WorkingWithDocument();
System::String outputDataDir = GetOutputDataDir_WorkingWithDocument();
// Load the template document.
System::SharedPtr<Document> doc = System::MakeObject<Document>(inputDataDir + u"TestFile.doc");
// Set view option.
doc->get_ViewOptions()->set_ViewType(ViewType::PageLayout);
doc->get_ViewOptions()->set_ZoomPercent(50);
System::String outputPath = outputDataDir + u"SetViewOption.doc";
// Save the finished document.
doc->Save(outputPath);

페이지 표시 옵션 설정

한 줄당 문자 수를 설정하려면 CharactersPerLine 재산. 당신은 또한 단어 문서에 대한 페이지 당 라인의 수를 설정할 수 있습니다- LinesPerPage 문서 표에서 페이지당 줄 수를 가져오거나 설정하는 속성입니다.

다음 코드 예제에서는 한 줄당 문자 수와 한 페이지당 줄 수를 설정하는 방법을 보여 줍니다 Microsoft Word 문서:

For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C
// The path to the documents directories.
System::String inputDataDir = GetInputDataDir_WorkingWithDocument();
System::String outputDataDir = GetOutputDataDir_WorkingWithDocument();
System::SharedPtr<Document> doc = System::MakeObject<Document>(inputDataDir + u"Document.doc");
//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->get_FirstSection()->get_PageSetup()->set_LayoutMode(SectionLayoutMode::Grid);
//Set the number of characters per line in the document grid.
doc->get_FirstSection()->get_PageSetup()->set_CharactersPerLine(30);
//Set the number of lines per page in the document grid.
doc->get_FirstSection()->get_PageSetup()->set_LinesPerPage(10);
System::String outputPath = outputDataDir + u"DocumentPageSetup.doc";
doc->Save(outputPath);

언어 기본 설정 설정

문서 표시 Microsoft Word 이 문서의 기본값으로 설정된 언어에 따라 다릅니다. 기본값에 언어가 설정되지 않은 경우, Microsoft Word 예를 들어,“파일,옵션,언어"에서 찾을 수 있는"사무실 언어 기본 설정 설정"대화 상자에서 정보를 가져옵니다. Microsoft Word 2019.

함께 Aspose.Words,당신은 또한 사용하여 언어 환경 설정을 설정할 수 있습니다 LanguagePreferences 수업 또한 문서의 올바른 표시를 위해 그것을 설정해야합니다 Microsoft Word 문서 로딩 프로세스가 일치해야하는 버전-이 작업을 사용하여 수행 할 수 있습니다. MswVersion 재산.

다음 코드 예제에서는 편집 언어에 일본어를 추가하는 방법을 보여 줍니다:

For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C
// Create a new LoadOptions object.
System::SharedPtr<LoadOptions> loadOptions = System::MakeObject<LoadOptions>();
// Set language preferences that will be used when document is loading.
loadOptions->get_LanguagePreferences()->AddEditingLanguage(EditingLanguage::Japanese);
System::SharedPtr<Document> doc = System::MakeObject<Document>(inputDataDir + u"languagepreferences.docx", loadOptions);

다음 코드 예제에서는 러시아어를 기본 편집 언어로 설정하는 방법을 보여 줍니다:

For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C
// The path to the documents directory.
System::SharedPtr<LoadOptions> loadOptions = System::MakeObject<LoadOptions>();
loadOptions->get_LanguagePreferences()->set_DefaultEditingLanguage(EditingLanguage::Russian);
System::SharedPtr<Document> doc = System::MakeObject<Document>(inputDataDir + u"languagepreferences.docx", loadOptions);
int32_t localeId = doc->get_Styles()->get_DefaultFont()->get_LocaleId();
if (localeId == static_cast<int32_t>(EditingLanguage::Russian))
{
std::cout << "The document either has no any language set in defaults or it was set to Russian originally." << std::endl;
}
else
{
std::cout << "The document default language was set to another than Russian language originally, so it is not overridden." << std::endl;
}

특정 단어 버전에 대한 문서 최적화

OptimizeFor 방법은 문서 내용뿐만 아니라,기본을 최적화 할 수 있습니다 Aspose.Words 특정 버전의 동작 Microsoft Word. 이 방법을 사용하여 다음을 방지 할 수 있습니다 Microsoft Word 문서 로드 시"호환성 모드"리본을 표시하지 않습니다. 당신은 또한 설정해야 할 수도 있습니다 Compliance 이전 또는 그 이상의 속성.

다음 코드 예제에서는 다음에 대한 문서 콘텐츠를 최적화하는 방법을 보여 줍니다 Microsoft Word 2016:

For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C
System::SharedPtr<Document> doc = System::MakeObject<Document>(inputDataDir + u"TestFile.docx");
doc->get_CompatibilityOptions()->OptimizeFor(MsWordVersion::Word2016);
System::String outputPath = outputDataDir + u"SetCompatibilityOptions.docx";
// Save the document to disk.
doc->Save(outputPath);