C# 如何更改Word語言設定

來源:互聯網
上載者:User

標籤: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語言設定

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.