Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sample for Excel - Shared with Script Lab
name: InsertWorkbook API Sample
description: Sample for Excel
author: jipyua
host: EXCEL
api_set: {}
script:
content: |
$('#file').change(insertWorkbook);
async function insertWorkbook() {
var myFile = document.getElementById("file");
var reader = new FileReader();
var time1 = null;
var time2 = null;
var ReaderTimerStart = null;
var readerTimerEnd = null;
reader.onload = (function (theFile) {
return function (e) {
readerTimerEnd = Date.now();
console.log("LoadingDoc Time: " + (readerTimerEnd - ReaderTimerStart))
Excel.run(function (context) {
console.log("here")
var startIndex = e.target.result.indexOf("base64,");
var mybase64 = e.target.result.substr(startIndex + 7, e.target.result.length);
time1 = Date.now();
context.workbook.worksheets.addFromBase64(mybase64);
return context.sync()
.then(function () {
time2 = Date.now();
console.log("Workbook insert Time:" + (time2 - time1) + " ms");
})
})
};
})(myFile.files[0]);
// Read in the image file as a data URL.
reader.readAsDataURL(myFile.files[0]);
ReaderTimerStart = Date.now();
// app.showNotification(document.getElementById(" bro").file);
}
/** Default helper for invoking an action and handling errors. */
async function tryCatch(callback) {
try {
await callback();
}
catch (error) {
OfficeHelpers.UI.notify(error);
OfficeHelpers.Utilities.log(error);
}
}
language: typescript
template:
content: "<form>\n\tSelect Workbook to be inserted <br> <input type=\"file\" id=\"file\">\n\t\n\n\n</form>"
language: html
style:
content: |
/* Your style goes here */
language: css
libraries: |
https://appsforoffice.microsoft.com/lib/beta/hosted/office.js
https://appsforoffice.microsoft.com/lib/beta/hosted/office.d.ts
office-ui-fabric-js@1.4.0/dist/css/fabric.min.css
office-ui-fabric-js@1.4.0/dist/css/fabric.components.min.css
core-js@2.4.1/client/core.min.js
@types/core-js
@microsoft/office-js-helpers@0.7.4/dist/office.helpers.min.js
@microsoft/office-js-helpers@0.7.4/dist/office.helpers.d.ts
jquery@3.1.1
@types/jquery
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment