Insert Content to Document in HTML Format
Code Examples
Example 1: Insert HTML in bookmark area
async function example1() {
const tableHtml = "<table><tbody><colgroup><col style='width:137.25pt'/></colgroup><tr><td><p>First cell content</p></td><td><p>Second cell content</p></td></tr></tbody></table>";
const bookmark = await app.ActiveDocument.Bookmarks.item("bm1");
const success = await bookmark.setHtml(tableHtml);
}
Example 2: Insert HTML in cell
async function example2() {
const htmlString = "<p>New content</p>";
const table = await app.ActiveDocument.Tables.item(1);
const row = await table.Rows.item(1);
const cell = await row.Cells.item(1);
const success = await cell.setHtml(htmlString);
}
Example 3: Insert HTML in current selection
async function example3() {
const htmlString = "<p>New content</p>";
const range = await app.ActiveDocument.getSelection();
await range.setHtml(htmlString);
}