Created
March 1, 2018 03:05
-
-
Save jipyua/7e9bcb16fdb1e266273eb03fec118606 to your computer and use it in GitHub Desktop.
Shared with Script Lab
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
name: Word createDoucment | |
description: '' | |
author: jipyua | |
host: WORD | |
api_set: {} | |
script: | |
content: | | |
$('#file').change(createDocument); | |
async function createDocument() { | |
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)) | |
Word.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.application.createDocument(mybase64).open(); | |
return context.sync() | |
.then(function () { | |
time2 = Date.now(); | |
console.log("Document Creation 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 document to be inserted <br> <input type=\"file\" id=\"file\">\n\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