標籤:localeid field c# subject esc ref day 西班牙語 spi
一般在建立或者開啟一個Word文檔時,如果沒有進行過特殊設定的話,系統預設的輸入語言的是英語輸入,但是為適應不同的辦公環境,我們其實是需要對文字嵌入的語言進行切換的,因此,本文將介紹如何使用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文檔進行語言設定方法的講述,文中對文檔的屬性設定在文檔的儲存與日後文件管理上其實也很有協助。希望本文能提供一定協助,歡迎轉載(轉載請註明出處)。感謝瀏覽!
C# 如何更改Word語言設定