Skip to content

Instantly share code, notes, and snippets.

@dmishin
Created April 15, 2021 18:08
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 dmishin/0ca3ace1f50869a505921f213cb1a1b6 to your computer and use it in GitHub Desktop.
Save dmishin/0ca3ace1f50869a505921f213cb1a1b6 to your computer and use it in GitHub Desktop.
$("#run").click(() => tryCatch(run));
async function run() {
Excel.run(async function (context) {
var sctivesheet = context.workbook.worksheets.getActiveWorksheet();
var table = sctivesheet.tables.add(sctivesheet.getRangeByIndexes(0, 0, 1, 2), true);
var data = [[1, "A"], [2, "B"], [3, "C"]];
table.rows.add(0, data);
}).catch(function (error) {
console.log("Error: " + error);
} )
}
/** Default helper for invoking an action and handling errors. */
async function tryCatch(callback) {
try {
await callback();
} catch (error) {
// Note: In a production add-in, you'd want to notify the user through your add-in's UI.
console.error(error);
}
}
@dmishin
Copy link
Author

dmishin commented Apr 15, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment