在Word 2013(桌面版)和office.js中工作时,我们会看到围绕用户选择的一些功能(GetSelectedDataAsync
,SetSelectedDataAsync
),但是没有什么可以让您查看整个(OpenXML)文档。我错过了什么吗?
答案 0 :(得分:3)
Office.context.document.getFileAsync
可让您以3种格式选择整个文档:
以下是MSDN的示例:
var i = 0;
var slices = 0;
function getDocumentAsPDF() {
Office.context.document.getFileAsync("pdf", { sliceSize: 2097152 }, function (result) {
if (result.status == "succeeded") {
// If the getFileAsync call succeeded, then
// result.value will return a valid File Object.
myFile = result.value;
slices = myFile.sliceCount;
document.getElementById("result").innerText = " File size:" + myFile.size + " #Slices: " + slices;
// Iterate over the file slices.
for (i = 0; i < slices; i++) {
var slice = myFile.getSliceAsync(i, function (result) {
if (result.status == "succeeded") {
doSomethingWithChunk(result.value.data);
if (slices == i) // Means it's done traversing...
{
SendFileComplete();
}
}
else
document.getElementById("result").innerText = result.error.message;
});
}
myFile.closeAsync();
}
else
document.getElementById("result2").innerText = result.error.message;
});
}