Ms office Office任务窗格应用程序:如何以OOXml字符串获取整个文档?

Ms office Office任务窗格应用程序:如何以OOXml字符串获取整个文档?,ms-office,office365,Ms Office,Office365,我正在开发一个Office任务窗格应用程序,需要访问整个文档。我知道有一个APIgetFileAsync() 但是,fileType只能是三个值:compressed,pdf,text 压缩的 以Office Open XML(OOXML)格式作为字节数组返回整个文档(.pptx或.docx) pdf 以字节数组的形式返回PDF格式的整个文档 text 仅以字符串形式返回文档的文本。(仅限文字) 压缩时,返回的值是字节数组。 如何获取OOXml字符串 或是否有一个API来选择文档中的所有内容,

我正在开发一个Office任务窗格应用程序,需要访问整个文档。我知道有一个API
getFileAsync()

但是,
fileType
只能是三个值:
compressed
pdf
text

压缩的

以Office Open XML(OOXML)格式作为字节数组返回整个文档(.pptx或.docx)

pdf

以字节数组的形式返回PDF格式的整个文档

text

仅以字符串形式返回文档的文本。(仅限文字)

压缩时,返回的值是字节数组。 如何获取OOXml字符串

是否有一个API来选择文档中的所有内容,以便我可以使用
getSelectedDataAsync()
API?

这有点晚了

我最近一直在使用任务窗格应用程序,结果证明OOXML是本机压缩的(除非我大错特错)


我最好的建议是找出字符串编码的编码,并用该编码类型进行解码。我愿意打赌它是UTF-8。

如果有人发现了这个线程,我会设法使用

var-dataByteArray=[];
函数getXML(){
Office.context.document.getFileAsync(“compressed”,{sliceSize:100000},函数(结果){
if(result.status==Office.AsyncResultStatus.successed){
//从结果中获取文件对象。
var myFile=result.value;
变量状态={
文件:myFile,
柜台:0,,
sliceCount:myFile.sliceCount
};
getSlice(state);
}
});
}
函数getSlice(状态){
state.file.getSliceAsync(state.counter,函数(结果){
if(result.status==Office.AsyncResultStatus.successed){
readSlice(result.value,state);
}
});
}
函数readSlice(切片,状态){
var data=slice.data;
//如果切片包含数据,则创建HTTP请求。
如果(数据){
dataByteArray=dataByteArray.concat(数据);
state.counter++;
if(state.counter0){
对于(变量i=0;i

希望将来会有一种更简单的方法。

将以下内容替换为PowerPoint:entry.filename==“ppt/presentation.xml”
Office.context.document.getFileAsync(fileType [, options], callback);
var dataByteArray = [];

function getDocumentAsOoxml() {
    Office.context.document.getFileAsync("compressed", { sliceSize: 100000 }, function (result) {
        if (result.status == Office.AsyncResultStatus.Succeeded) {
            // Get the File object from the result.
            var myFile = result.value;
            var state = {
                file: myFile,
                counter: 0,
                sliceCount: myFile.sliceCount
            };
            getSlice(state);
        }
    });
}

function getSlice(state) {
    state.file.getSliceAsync(state.counter, function (result) {
        if (result.status == Office.AsyncResultStatus.Succeeded) {
            readSlice(result.value, state);
        }
    });
}

function readSlice(slice, state) {
    var data = slice.data;
    // If the slice contains data, create an HTTP request.
    if (data) {
        dataByteArray = dataByteArray.concat(data);
        state.counter++;
        if (state.counter < state.sliceCount) {
            getSlice(state);
        } else {
            closeFile(state);
        }
    }
}

function closeFile(state) {
    // Close the file when you're done with it.
    state.file.closeAsync(function (result) { });

    // convert from byte array to blob that can bre read by zip.js
    var byteArray = new Uint8Array(dataByteArray);
    var blob = new Blob([byteArray]);

    // Load zip.js library
    $.getScript("/Scripts/zip.js/zip.js", function () {
        zip.workerScriptsPath = "/Scripts/zip.js/";
        // use a BlobReader to read the zip from a Blob object
        zip.createReader(new zip.BlobReader(blob), function (reader) {
            // get all entries from the zip file
            reader.getEntries(function (entries) {
                if (entries.length > 0) {
                    for (var i = 0; i < entries.length; i++) {
                        var entry = entries[i];
                        // find the file you are looking for
                        if (entry.filename == 'word/document.xml') {
                            entry.getData(new zip.TextWriter(), function (text) {

                                // text contains the entry data as a String
                                doSomethingWithText(text);

                                // close the zip reader
                                reader.close(function () {
                                    // onclose callback
                                });
                            }, function (current, total) {
                                // onprogress callback
                            });
                            break;
                        }
                    }
                }
            });
        }, function (error) {
            // onerror callback
        });
    });
}