博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[.NET开发] C# 如何更改Word语言设置
阅读量:4582 次
发布时间:2019-06-09

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

  一般在创建或者打开一个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到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,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");

  复制代码

  (编辑:雷林鹏 来源:网络)

转载于:https://www.cnblogs.com/pengpeng1208/p/9232933.html

你可能感兴趣的文章
lnmp集成开发环境安装pdo_dblib扩展
查看>>
linux web.py spawn-fcgi web.py 配置
查看>>
lintcode : 空格替换
查看>>
lintcode 中等题:subsets II 带重复元素的子集
查看>>
【原创】Linux基础之测试域名IP端口连通性
查看>>
webstorm快捷键大全
查看>>
SQL Server 语法大全
查看>>
MySQL存储过程
查看>>
HttpContext是干什么的
查看>>
线程安全
查看>>
原形模式
查看>>
iOS开发笔记5:多线程之NSThread、NSOperation及GCD
查看>>
php中curl的详细解说【转】
查看>>
Codeforces Round #281 (Div. 2) C. Vasya and Basketball 二分
查看>>
hdu 6069 Counting Divisors 筛法
查看>>
codeforces gym 100971 K Palindromization 思路
查看>>
各个控件说明
查看>>
鼠标事件(jQuery)
查看>>
delete指针时coredump的分析之旅
查看>>
openoffice+pdf2swf+FlexPaper在线显示office和pdf
查看>>