Word Belgelerinin Seçenekleri ve Görünümüyle Çalışma

Bazen bir belgenin görünümünü değiştirmeniz gerekebilir, örneğin dil tercihlerini veya sayfa başına satır sayısını ayarlayın.Aspose.Words, belgenin nasıl görüntüleneceğini ve bazı ek seçenekleri kontrol etme olanağı sağlar. Bu makalede, bu tür olasılıklar açıklanmaktadır.

Belge Görüntüleme Seçeneklerini Ayarlama

ViewOptions sınıfını kullanarak bir belgenin Microsoft Word içinde nasıl görüntüleneceğini kontrol edebilirsiniz. Örneğin, ZoomPercent özelliğini kullanarak bir belge yakınlaştırma değeri veya ViewType özelliğini kullanarak görünüm modunu ayarlayabilirsiniz.

Aşağıdaki kod örneği, Microsoft Word içinde açıldığında bir belgenin % 50 oranında görüntülenmesini nasıl sağlayacağınızı gösterir.:

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);

Sayfa Görüntüleme Seçeneklerini Ayarlama

Satır başına karakter sayısını ayarlamak istiyorsanız, CharactersPerLine özelliğini kullanın. Bir Word belgesinin sayfa başına satır sayısını da ayarlayabilirsiniz - belge kılavuzundaki sayfa başına satır sayısını almak veya ayarlamak için LinesPerPage özelliğini kullanın.

Aşağıdaki kod örneği, Microsoft Word belgesi için satır başına karakter sayısını ve sayfa başına satır sayısını nasıl ayarlayacağınızı gösterir:

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);

Dil Tercihlerini Ayarlama

Bir belgenin Microsoft Word içinde görüntülenmesi, bu belge için hangi dillerin varsayılan olarak ayarlandığına bağlıdır. Varsayılan olarak hiçbir dil ayarlanmamışsa, Microsoft Word, örneğin Microsoft Word 2019’daki “Dosya → Seçenekler → Dil” altında bulunabilen “Office Dil Tercihlerini Ayarla” iletişim kutusundan bilgi alır.

Aspose.Words ile LanguagePreferences sınıfını kullanarak dil tercihlerini de ayarlayabilirsiniz. Ayrıca, belgenizin doğru görüntülenmesi için belge yükleme işleminin eşleşmesi gereken Microsoft Word sürümünü ayarlamanız gerektiğini unutmayın – bu, MswVersion özelliği kullanılarak yapılabilir.

Aşağıdaki kod örneği, düzenleme dillerine Japonca nasıl ekleneceğini gösterir:

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);

Aşağıdaki kod örneği, Rusça’nın varsayılan düzenleme dili olarak nasıl ayarlanacağını gösterir:

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;
}

Belgeyi Belirli Bir Word Sürümü için Optimize Etme

OptimizeFor yöntemi, belge içeriğinin optimize edilmesine ve Microsoft Word’ün belirli bir sürümü için varsayılan Aspose.Words davranışına izin verir. Belge yüklenirken Microsoft Word ‘ün “Uyumluluk modu” şeridini görüntülemesini önlemek için bu yöntemi kullanabilirsiniz. Compliance özelliğini Iso29500_2008_Transitional veya üstü olarak ayarlamanız gerekebileceğini unutmayın.

Aşağıdaki kod örneği, Microsoft Word 2016 için belge içeriğinin nasıl optimize edileceğini gösterir:

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);