跳到主要内容

SetLanguage

指定处理当前段落内容时用于检查拼写和语法(如果请求)的语言。

语法​

expression.SetLanguage(langId);

expression - 表示 ApiParagraph 类的变量。

参数​

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

返回值​

ApiParagraph | null

示例​

为电子表格中形状内的段落设置拼写检查语言。

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

// Set the language of the paragraph and print it in a spreadsheet.

const worksheet = Api.GetActiveSheet();
const fill = Api.CreateSolidFill(Api.RGB(160, 100, 110));
const stroke = Api.CreateStroke(0, Api.CreateNoFill());
const shape = worksheet.AddShape(
'roundRect',
Api.MillimetersToEmus(90), Api.MillimetersToEmus(40),
fill, stroke,
0, 0, 2, 0
);

const content = shape.GetContent();
const paragraph = content.GetElement(0);
paragraph.AddText('This is a paragraph with the spell-check language set.');
paragraph.SetLanguage('en-CA');

const resultParagraph = Api.CreateParagraph();
resultParagraph.AddText('Paragraph language: ' + shape.GetTextRange().GetTextPr().GetLanguage());
content.Push(resultParagraph);