Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Last active July 25, 2022 11:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjoerntx/d4114f9a68d161ecf76aef99d85bf1f5 to your computer and use it in GitHub Desktop.
Save bjoerntx/d4114f9a68d161ecf76aef99d85bf1f5 to your computer and use it in GitHub Desktop.
function insertTableWithText() {
// start the undo action (open group)
TXTextControl.beginUndoAction("Table insertion");
// add a table
TXTextControl.tables.add(5, 5, 10, function(e) {
if (e === true) { // if added
TXTextControl.tables.getItem(async function(table) {
console.log("setting cell text...");
// async setting of cell text
await setCellText(table);
console.log("setting cell text done.");
// stop the undo action (close group)
TXTextControl.endUndoAction();
}, null, 10);
}
})
}
function setCellText(table) {
return new Promise(resolve => {
table.cells.getCount(function(count) {
// loop through all table cells
for (let i = 0; i < count; i++) {
table.cells.elementAt(i, function(cell) {
console.log("setting text for cell " + i);
cell.setText("Cell " + i);
// resolve on last cell
if (i == count - 1) {
resolve();
}
});
}
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment