Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
$("#file").change(() => tryCatch(insertSheets));
async function insertSheets() {
const myFile = <HTMLInputElement>document.getElementById("file");
const reader = new FileReader();
reader.onload = (event) => { => {
// strip off the metadata before the base64-encoded string
const startIndex = (<string>(<FileReader>"base64,");
const workbookContents = (<string>(<FileReader> + 7);
const sheets = context.workbook.worksheets;
null, // get all the worksheets
Excel.WorksheetPositionType.end // insert them after the current workbook's worksheets
return context.sync();
// read in the file as a data URL so we can parse the base64-encoded string
/** 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment