Skip to content

Instantly share code, notes, and snippets.

@jipyua
Created November 2, 2018 01:48
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 jipyua/caec8eb5fddc0f611c43a1dbb356fa2a to your computer and use it in GitHub Desktop.
Save jipyua/caec8eb5fddc0f611c43a1dbb356fa2a to your computer and use it in GitHub Desktop.
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
@divishav
Copy link

Hi! We tried using context.workbook.worksheets.addFromBase64(mybase64) and it gives This operation is not implemented error. We have Beta CDN for Office JS and excel-web-16.00.js. Are we missing something here?

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