博客
关于我
C# 如何更改Word语言设置
阅读量:413 次
发布时间:2019-03-06

本文共 1933 字,大约阅读时间需要 6 分钟。

一般在创建或者打开一个Word文档时,如果没有进行过特殊设置的话,系统默认的输入语言是英语输入。但为了适应不同的办公环境,我们需要对文字嵌入的语言进行切换。本文将介绍如何使用免费版组件来实现Word语言输入。此外,本文还将演示该组件的多种Word操作功能,如设置文档属性、文档视图模式等。

代码操作前准备

安装Spire.Doc for .NET之后,需要将Spire.Doc.dll文件添加到项目程序集,并在命名空间中添加相应的using指令。

注意:以下代码以选取西班牙语(秘鲁)为例,其他语言设置可参考相应文档。

具体步骤如下:

步骤一:添加如下命名空间

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

步骤二:更改文本输入语言

//创建一个Document类实例,并添加Section和Paragraph到Document  
Document 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,\ny 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文档进行语言设置方法的讲述。文中对文档的属性设置在文档的保存与日后文档管理上其实也很有帮助。希望本文能提供一定帮助,欢迎转载(转载请注明出处)。感谢浏览!

你可能感兴趣的文章
NN&DL4.8 What does this have to do with the brain?
查看>>
nnU-Net 终极指南
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
NO 157 去掉禅道访问地址中的zentao
查看>>
no available service ‘default‘ found, please make sure registry config corre seata
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>
No module named 'crispy_forms'等使用pycharm开发
查看>>
No module named cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>
No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
查看>>
No new migrations found. Your system is up-to-date.
查看>>
No qualifying bean of type XXX found for dependency XXX.
查看>>
No resource identifier found for attribute 'srcCompat' in package的解决办法
查看>>
no session found for current thread
查看>>
No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
查看>>