ToHtml
将文本范围转换为 HTML。
语法
expression.ToHtml(options);
expression - 表示 ApiTextRange 类的变量。
参数
| 名称 | 必需/可选 | 数据类型 | 默认值 | 描述 |
|---|---|---|---|---|
| options | 可选 | ToHtmlOptions | {} | HTML 转换选项。 |
返回值
string
示例
在电子表格中将段落的一部分导出为 HTML 字符串。
// How do I get the HTML markup of only a fragment of the text in a spreadsheet?
// Convert the end of a sentence with its bold words to HTML and write the markup to a cell in a spreadsheet.
const worksheet = Api.GetActiveSheet();
const fill = Api.CreateSolidFill(Api.RGB(255, 111, 61));
const stroke = Api.CreateStroke(0, Api.CreateNoFill());
const shape = worksheet.AddShape("rect", 120 * 36000, 70 * 36000, fill, stroke, 0, 2 * 36000, 2, 3 * 36000);
const paragraph = shape.GetContent().GetElement(0);
paragraph.AddText("Convert only ");
const boldRun = paragraph.AddText("this part");
boldRun.SetBold(true);
const range = paragraph.GetTextRange(8, 22);
const html = range.ToHtml({"RenderHTMLTags": true});
worksheet.GetRange("A1").SetValue("HTML output: " + html.trim());