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

本文共 1892 字,大约阅读时间需要 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到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文档进行语言设置方法的讲述,文中对文档的属性设置在文档的保存与日后文档管理上其实也很有帮助。希望本文能提供一定帮助,欢迎转载(转载请注明出处)。感谢浏览!

 

你可能感兴趣的文章
Webpack 之 basic chunk graph
查看>>
Mysql5.7版本单机版my.cnf配置文件
查看>>
mysql5.7的安装和Navicat的安装
查看>>
mysql5.7示例数据库_Linux MySQL5.7多实例数据库配置
查看>>
Mysql8 数据库安装及主从配置 | Spring Cloud 2
查看>>
mysql8 配置文件配置group 问题 sql语句group不能使用报错解决 mysql8.X版本的my.cnf配置文件 my.cnf文件 能够使用的my.cnf配置文件
查看>>
MySQL8.0.29启动报错Different lower_case_table_names settings for server (‘0‘) and data dictionary (‘1‘)
查看>>
MYSQL8.0以上忘记root密码
查看>>
Mysql8.0以上重置初始密码的方法
查看>>
mysql8.0新特性-自增变量的持久化
查看>>
Mysql8.0注意url变更写法
查看>>
Mysql8.0的特性
查看>>
MySQL8修改密码报错ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
查看>>
MySQL8修改密码的方法
查看>>
Mysql8在Centos上安装后忘记root密码如何重新设置
查看>>
Mysql8在Windows上离线安装时忘记root密码
查看>>
MySQL8找不到my.ini配置文件以及报sql_mode=only_full_group_by解决方案
查看>>
mysql8的安装与卸载
查看>>
MySQL8,体验不一样的安装方式!
查看>>
MySQL: Host '127.0.0.1' is not allowed to connect to this MySQL server
查看>>