Last active
July 25, 2022 11:32
-
-
Save bjoerntx/d4114f9a68d161ecf76aef99d85bf1f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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