一般在創建或者打開一個Word文檔時,如果沒有進行過特殊設置的話,系統默認的輸入語言的是英語輸入,但是為適應不同的辦公環境,我們其實是需要對文字嵌入的語言進行切換的,因此,本文將介紹如何使用免費版組件Free Spire.Doc for .NET來實現Word語言輸入。另外,針對這款組件的多種Word操作功能,如,設置文檔屬性、文檔視圖模式等,本文中也將作進一步演示演示。
代碼操作前準備
安裝Spire.Doc for .NET之后,添加引用Spire.Doc.dll文件到項目程序集,同時添加相應的using指令到命名空間。
注意:以下代碼中,以選取西班牙語(秘魯)為例,其他語言設置,可參見 Microsoft Locale ID Values
具體步驟如下:
步驟一:添加如下命名空間
using System;using Spire.Doc;using Spire.Doc.Documents;using Spire.Doc.Fields;
步驟二:更改文本輸入語言
//創建一個Document類實例,并添加Section和Paragraph到DocumentDocument doc = new Document();Section sec = doc.AddSection();Paragraph para = sec.AddParagraph();//向段落添加西班牙(秘魯)語文字并設置文本對齊方式TextRange txtRange = para.AppendText("Puedo escribir los versos más tristes esta noche./n Escribir, por ejemplo: La noche está estrellada,y tiritan, azules, los astros, a lo lejos./n El viento de la noche gira en el cielo y canta./n Puedo escribir los versos más tristes esta noche.");txtRange.CharacterFormat.LocaleIdASCII= 10250;para.Format.HorizontalAlignment = HorizontalAlignment.Center;
步驟三:設置試圖模式為Web視圖,調整視圖縮放比例
doc.ViewSetup.DocumentViewType = DocumentViewType.WebLayout;doc.ViewSetup.ZoomPercent = 120;doc.ViewSetup.ZoomType = ZoomType.None;
步驟四:添加文檔屬性(可根據需要自行設置文檔內置屬性或者自定義屬性)
//添加文檔屬性(內置屬性)doc.BuiltinDocumentProperties.Title = "測試文件";doc.BuiltinDocumentProperties.Category = "非機密文檔";doc.BuiltinDocumentProperties.Author = "James";doc.BuiltinDocumentProperties.LastAuthor = "Mia";doc.BuiltinDocumentProperties.Keywords = "Word文檔, 屬性, 樣本";doc.BuiltinDocumentProperties.Comments = "此文檔僅供測試使用";doc.BuiltinDocumentProperties.Subject = "Demo";//添加文檔屬性(自定義屬性)CustomDocumentProperties custom = doc.CustomDocumentProperties;custom.Add("Authorized Date", DateTime.Today);
步驟五:保存并打開文檔
doc.SaveToFile("Sample.doc", FileFormat.Doc);System.Diagnostics.Process.Start("Sample.doc");
完成以上步驟后,運行該項目生成文件(可在該項目文件夾下bin>Debug下查看),如下圖所示:
對文檔屬性的設置如下圖所示:
以上全部內容為本次對Word文檔進行語言設置方法的講述,文中對文檔的屬性設置在文檔的保存與日后文檔管理上其實也很有幫助。希望本文能提供一定幫助,感謝瀏覽!
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。
|
新聞熱點
疑難解答