Last active
October 20, 2021 13:07
-
-
Save nermin-slidelizard/16cf8280da004e5e3908d7f23bc78a23 to your computer and use it in GitHub Desktop.
Create a new snippet from a blank template.
This file contains hidden or 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: Blank snippet | |
| description: Create a new snippet from a blank template. | |
| host: POWERPOINT | |
| api_set: {} | |
| script: | |
| content: >- | |
| getDocumentAsCompressed(); | |
| function getDocumentAsCompressed() { | |
| Office.context.document.getFileAsync(Office.FileType.Compressed, { sliceSize: 4_096_000 /*64 KB*/ }, | |
| function (result) { | |
| if (result.status == Office.AsyncResultStatus.Succeeded) { | |
| // If the getFileAsync call succeeded, then | |
| // result.value will return a valid File Object. | |
| var myFile = result.value; | |
| var sliceCount = myFile.sliceCount; | |
| var slicesReceived = 0, gotAllSlices = true, docdataSlices = []; | |
| console.log("File size:" + myFile.size + " #Slices: " + sliceCount); | |
| // Get the file slices. | |
| getSliceAsync(myFile, 0, sliceCount, gotAllSlices, docdataSlices, slicesReceived); | |
| } | |
| else { | |
| console.log("Error:", result.error.message); | |
| } | |
| }); | |
| } | |
| function getSliceAsync(file, nextSlice, sliceCount, gotAllSlices, | |
| docdataSlices, slicesReceived) { | |
| file.getSliceAsync(nextSlice, function (sliceResult) { | |
| if (sliceResult.status == "succeeded") { | |
| if (!gotAllSlices) { // Failed to get all slices, no need to continue. | |
| return; | |
| } | |
| // Got one slice, store it in a temporary array. | |
| // (Or you can do something else, such as | |
| // send it to a third-party server.) | |
| docdataSlices[sliceResult.value.index] = sliceResult.value.data; | |
| if (++slicesReceived == sliceCount) { | |
| // All slices have been received. | |
| file.closeAsync(); | |
| onGotAllSlices(docdataSlices); | |
| } | |
| else { | |
| getSliceAsync(file, ++nextSlice, sliceCount, gotAllSlices, docdataSlices, slicesReceived); | |
| } | |
| } | |
| else { | |
| gotAllSlices = false; | |
| file.closeAsync(); | |
| console.log("getSliceAsync Error:", sliceResult.error.message); | |
| } | |
| }); | |
| } | |
| function onGotAllSlices(docdataSlices) { | |
| var docdata = []; | |
| for (var i = 0; i < docdataSlices.length; i++) { | |
| docdata = docdata.concat(docdataSlices[i]); | |
| } | |
| var fileContent = new String(); | |
| for (var j = 0; j < docdata.length; j++) { | |
| fileContent += String.fromCharCode(docdata[j]); | |
| } | |
| // Now all the file content is stored in 'fileContent' variable, | |
| // you can do something with it, such as print, fax... | |
| } | |
| // The following example gets the document in PDF format. | |
| Office.context.document.getFileAsync(Office.FileType.Pdf, | |
| function (result) { | |
| if (result.status == Office.AsyncResultStatus.Succeeded) { | |
| var myFile = result.value; | |
| var sliceCount = myFile.sliceCount; | |
| console.log("File size:" + myFile.size + " #Slices: " + sliceCount); | |
| // Now, you can call getSliceAsync to download the files, | |
| // as described in the previous code segment (compressed format). | |
| myFile.closeAsync(); | |
| } | |
| else { | |
| console.log("Error:", result.error.message); | |
| } | |
| } | |
| ); | |
| language: typescript | |
| template: | |
| content: | | |
| <button id="run" class="ms-Button"> | |
| <span class="ms-Button-label">Run</span> | |
| </button> | |
| language: html | |
| style: | |
| content: |- | |
| section.samples { | |
| margin-top: 20px; | |
| } | |
| section.samples .ms-Button, section.setup .ms-Button { | |
| display: block; | |
| margin-bottom: 5px; | |
| margin-left: 20px; | |
| min-width: 80px; | |
| } | |
| language: css | |
| libraries: | | |
| https://appsforoffice.microsoft.com/lib/beta/hosted/office.js | |
| @types/office-js | |
| 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 | |
| jquery@3.1.1 | |
| @types/jquery@3.3.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment