How C # changes Word language settings

Source: Internet
Author: User

Generally when creating or opening a Word document, if no special settings have been made, the system default input language is English input, but in order to adapt to different office environment, we actually need to change the language embedded in the text, so this article will describe how to use spire.doc for. NET to implement word language input. In addition, a variety of word manipulation features for this component, such as setting document properties, document view modes, and more, will be demonstrated in this article.

Before the code is ready for operation:
Install Spire.doc for. NET, add a reference to the Spire.Doc.dll file to the project assembly, adding the appropriate using directives to the namespace.
Note In the following code, to select Spanish (Peru) For example, other language settings are available in the Microsoft locale ID Values

The steps are as follows:
Step One: Add the following namespaces

using System;using Spire.Doc;using Spire.Doc.Documents;using Spire.Doc.Fields;

Step Two: Change the text input language

//创建一个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;

Step three: Set the attempt mode to Web view, adjust the view scale

doc.ViewSetup.DocumentViewType = DocumentViewType.WebLayout;doc.ViewSetup.ZoomPercent = 120;doc.ViewSetup.ZoomType = ZoomType.None;

Step four: Add document properties (you can set your own document built-in properties or custom properties as needed)

//添加文档属性(内置属性)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);

Step five: Save and open the document

doc.SaveToFile("Sample.doc", FileFormat.Doc);System.Diagnostics.Process.Start("Sample.doc");

After you complete the steps above, run the project build file (which can be viewed under Bin>debug under the project folder) as shown in:

The settings for document properties are as follows:

All of the above is the language of the Word document to set the method of the description, the document's property settings in the document preservation and future document management is actually very helpful. Hope this article can provide certain help, welcome reprint (Reprint please indicate source). Thanks for browsing!

How C # changes Word language settings

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.