עבודה עם אפשרויות והופעת מסמכי Word

לפעמים אתה יכול לשנות את המראה של מסמך, למשל, להגדיר העדפות שפה או מספר השורות בעמוד.Aspose.Words מספק את היכולת לשלוט כיצד המסמך יוצג, כמו גם כמה אפשרויות נוספות. מאמר זה מתאר אפשרויות כאלה.

הגדרת אפשרויות תצוגה

אתה יכול לשלוט איך מסמך יופיע Microsoft Word באמצעות ViewOptions מעמד. לדוגמה, באפשרותך להגדיר ערך OOm מסמך באמצעות מסמך ZoomPercent רכוש, או מצב התצוגה באמצעות ViewType רכוש.

דוגמה לקוד הבא מראה כיצד להבטיח כי מסמך מוצג ב-50% כאשר נפתח בשנת Microsoft Word:

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_WorkingWithDocument();
// Load the template document.
Document doc = new Document(dataDir + "TestFile.doc");
// Set view option.
doc.ViewOptions.ViewType = ViewType.PageLayout;
doc.ViewOptions.ZoomPercent = 50;
dataDir = dataDir + "TestFile.SetZoom_out.doc";
// Save the finished document.
doc.Save(dataDir);

הגדרות Page Display Options

אם אתה רוצה להגדיר את מספר הדמויות לכל קו, השתמש CharactersPerLine רכוש. באפשרותך גם להגדיר את מספר השורות בדף עבור מסמך Word - להשתמש LinesPerPage רכוש כדי לקבל או להגדיר את מספר השורות בעמוד ברשת המסמך.

הדוגמה הקודית הבאה מראה כיצד להגדיר את מספר הדמויות לשורה ואת מספר השורות בעמוד Microsoft Word מסמך:

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_WorkingWithDocument();
Document doc = new Document(dataDir + "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.FirstSection.PageSetup.LayoutMode = SectionLayoutMode.Grid;
//Set the number of characters per line in the document grid.
doc.FirstSection.PageSetup.CharactersPerLine = 30;
//Set the number of lines per page in the document grid.
doc.FirstSection.PageSetup.LinesPerPage = 10;
dataDir = dataDir + "Document.PageSetup_out.doc";
doc.Save(dataDir);

הגדרות שפה

הצגת מסמך Microsoft Word תלוי אילו שפות מוגדרות כברירת מחדל עבור מסמך זה. אם אין שפות מוגדרות כברירת מחדל, Microsoft Word לוקח מידע מתיבת הדו-שיח “Set Office Language Preferences” אשר, לדוגמה, ניתן למצוא תחת “File s אפשרויות שפה” ב 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-.NET
// Create a new LoadOptions object.
LoadOptions loadOptions = new LoadOptions();
// Set language preferences that will be used when document is loading.
loadOptions.LanguagePreferences.AddEditingLanguage(EditingLanguage.Japanese);
Document doc = new Document(dataDir + @"languagepreferences.docx", loadOptions);

דוגמה לקוד הבא מראה כיצד להגדיר רוסית כשפת העריכה ברירת המחדל:

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET
// The path to the documents directory.
LoadOptions loadOptions = new LoadOptions();
loadOptions.LanguagePreferences.DefaultEditingLanguage = EditingLanguage.Russian;
Document doc = new Document(dataDir + @"languagepreferences.docx", loadOptions);
int localeId = doc.Styles.DefaultFont.LocaleId;
if (localeId == (int)EditingLanguage.Russian)
Console.WriteLine("The document either has no any language set in defaults or it was set to Russian originally.");
else
Console.WriteLine("The document default language was set to another than Russian language originally, so it is not overridden.");

עקבו אחרי a Particular גירסה Word

The The The OptimizeFor שיטה מאפשרת אופטימיזציה של תוכן מסמך, כמו גם ברירת מחדל Aspose.Words התנהגות לגרסה מסוימת של Microsoft Word. ניתן להשתמש בשיטה זו כדי למנוע Microsoft Word מהצגת “מצב תאימות” ribbon על טעינת מסמכים. שימו לב שגם אתם צריכים להגדיר את Compliance נכס Iso29500_2008_Transitional או גבוה יותר.

הדוגמה הבאה של הקוד מראה כיצד לייעל תוכן מסמך עבור Microsoft Word 2016:

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET
Document doc = new Document(fileName);
doc.CompatibilityOptions.OptimizeFor(Settings.MsWordVersion.Word2016);
dataDir = dataDir + RunExamples.GetOutputFilePath(fileName);
// Save the document to disk.
doc.Save(dataDir);