العمل مع خيارات ومظهر وثائق كلمة
قد تحتاج أحيانا إلى تغيير مظهر المستند، على سبيل المثال، تعيين تفضيلات اللغة أو عدد الأسطر في كل صفحة.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 يأخذ معلومات من مربع الحوار" تعيين تفضيلات لغة المكتب “، والذي، على سبيل المثال، يمكن العثور عليه ضمن” ملف Options خيارات Language لغة " في 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
إلى إيزو 29500_2008_ ترانزيتيونال أو أعلى.
يوضح مثال الكود التالي كيفية تحسين محتوى المستند لـ 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); |