ทำงานกับตัวเลือกและลักษณะของเอกสารคำ

บางครั้งคุณอาจต้องเปลี่ยนลักษณะที่ปรากฏของเอกสารตัวอย่างเช่นตั้งค่ากำหนดภาษาห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-Java
Document doc = new Document(dataDir + "Document.doc");
doc.getViewOptions().setViewType(ViewType.PAGE_LAYOUT);
doc.getViewOptions().setZoomPercent(50);
doc.save(dataDir + "Document.SetZoom_out.doc");

ตั้งค่าตัวเลือกการแสดงหน้าเว็บ

หากคุณต้องการตั้งค่าจำนวนอักขระต่อบรรทัดให้ใช้คุณสมบัติCharactersPerLine นอกจากนี้คุณยังสามารถตั้งค่าจำนวนบรรทัดต่อหน้าสำหรับเอกสารคำ–ใช้คุณสมบัติLinesPerPageเพื่อรับ.

ตัวอย่างรหัสต่อไปนี้แสดงวิธีการตั้งค่าจำนวนอักขระต่อบรรทัดและจำนวนบรรทัดต่อหน้าสำหรับเอกสารMicrosoft Word:

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java
// The path to the documents directory.
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.getFirstSection().getPageSetup().setLayoutMode(SectionLayoutMode.GRID);
// Set the number of characters per line in the document grid.
doc.getFirstSection().getPageSetup().setCharactersPerLine(30);
// Set the number of lines per page in the document grid.
doc.getFirstSection().getPageSetup().setLinesPerPage(10);
// Save the document
doc.save(dataDir + "Document.PageSetup_out.doc");

ตั้งค่าการตั้งค่าภาษา

การแสดงเอกสารในMicrosoft Wordขึ้นอยู่กับการตั้งค่าภาษาใดเป็นค่าดีฟอลต์สำหรับเอกสารนี้ หากไม่มีการตั้งค่าภาษาเป็นค่าเริ่มต้นMicrosoft Wordจะใช้ข้อมูลจากกล่องโต้ตอบ"ตั้งค่าการตั้งค่าภาษาสำนักงาน"ซึ่งสามารถพบได้ภายใต้"ตัวเลือกไฟล์ Language→ภาษา"ในMicrosoft Word2019.

ด้วยAspose.Wordsคุณยังสามารถตั้งค่าการกำหนดลักษณะภาษาโดยใช้ชั้นเรียนLanguagePreferences นอกจากนี้โปรดทราบว่าสำหรับการแสดงผลที่ถูกต้องของเอกสารของคุณจำเป็นต้องตั้งค่าเวอร์ชันMicrosoft Wordที่กระบวนการโหลดเอกสารควรตรงกันซึ่งสามารถทำได้โดยใช้คุณสมบัติMswVersion.

ตัวอย่างรหัสต่อไปนี้แสดงวิธีเพิ่มภาษาญี่ปุ่นในการแก้ไขภาษา:

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java
// Specify LoadOptions to add Editing Language
LoadOptions loadOptions = new LoadOptions();
loadOptions.getLanguagePreferences().addEditingLanguage(EditingLanguage.JAPANESE);
Document doc = new Document(dataDir + "languagepreferences.docx", loadOptions);
int localeIdFarEast = doc.getStyles().getDefaultFont().getLocaleIdFarEast();
if (localeIdFarEast == (int) EditingLanguage.JAPANESE)
System.out.println("The document either has no any FarEast language set in defaults or it was set to Japanese originally.");
else
System.out.println("The document default FarEast language was set to another than Japanese language originally, so it is not overridden.");

ตัวอย่างรหัสต่อไปนี้แสดงวิธีการตั้งภาษารัสเซียเป็นภาษาการแก้ไขเริ่มต้น:

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java
// Specify LoadOptions to set Default Editing Language
LoadOptions loadOptions = new LoadOptions();
loadOptions.getLanguagePreferences().setDefaultEditingLanguage(EditingLanguage.RUSSIAN);
Document doc = new Document(dataDir + "languagepreferences.docx", loadOptions);
int localeId = doc.getStyles().getDefaultFont().getLocaleId();
if (localeId == (int) EditingLanguage.RUSSIAN)
System.out.println("The document either has no any language set in defaults or it was set to Russian originally.");
else
System.out.println("The document default language was set to another than Russian language originally, so it is not overridden.");

การบริหารจัดการโปรเจค

วิธีOptimizeForอนุญาตให้เพิ่มประสิทธิภาพเนื้อหาของเอกสารรวมทั้งพฤติกรรมเริ่มต้นAspose.Wordsสำหรับเวอร์ชันใดเวอร์ชันหนึ่งของMicrosoft Word คุณสามารถใช้วิธีนี้เพื่อป้องกันไม่ให้Microsoft Wordแสดงริบบิ้น"โหมดความเข้ากันได้"เมื่อโหลดเอกสาร โปรดทราบว่าคุณอาจต้องตั้งค่าคุณสมบัติComplianceเป็นIso29500_2008_Transitionalหรือสูงกว่า.

ตัวอย่างรหัสต่อไปนี้แสดงวิธีการเพิ่มประสิทธิภาพเนื้อหาเอกสารสำหรับMicrosoft Word2016:

Document doc = new Document(dataDir + "Document.docx");

// Set Word2016 version for document
doc.getCompatibilityOptions().optimizeFor(MsWordVersion.WORD_2016);

// Save the document.
doc.save(dataDir + "output.docx");