跳到主要内容

SetLanguage

指定在处理文本块内容时将用于检查拼写和语法(如果请求)的语言。

继承自 ApiTextPr.SetLanguage。

语法​

expression.SetLanguage(langId);

expression - 表示 ApiRangeTextPr 类的变量。

参数​

名称必需/可选数据类型默认值描述
langId必需string | null此参数的可能值为 RFC 4646/BCP 47 定义的语言标识符。示例:"en-CA"。传递 null 可移除语言。

返回值​

ApiTextPr

示例​

为文档中的文本分配拼写检查语言。

// How do I tell the editor which language to use when checking text in a document?

// Ensure correct spelling and grammar rules by setting the text language in a document.

let doc = Api.GetDocument();
let textPr = doc.GetDefaultTextPr();
textPr.SetLanguage("en-CA");
let paragraph = doc.GetElement(0);
let run = Api.CreateRun();
run.AddText("This is just a sample text. ");
paragraph.AddElement(run);
run = Api.CreateRun();
run.AddText("This is a text run with the text language set to English (Canada).");
run.SetTextPr(textPr);
paragraph.AddElement(run);