Share via


Office.FileType enum

Especifica o formato no qual o documento deve ser retornado.

Comentários

Exemplos

// The following example gets the document in Office Open XML ("compressed") format in 65536 bytes (64 KB) slices.
// Note: The implementation of app.showNotification in this example is from the Visual Studio template for Office Add-ins.
function getDocumentAsCompressed() {
    Office.context.document.getFileAsync(Office.FileType.Compressed, { sliceSize: 65536 /*64 KB*/ }, 
        function (result) {
            if (result.status == "succeeded") {
                // If the getFileAsync call succeeded, then
                // result.value will return a valid File Object.
                const myFile = result.value;
                const sliceCount = myFile.sliceCount;
                const docDataSlices = [];
                let slicesReceived = 0, gotAllSlices = true;
                app.showNotification("File size:" + myFile.size + " #Slices: " + sliceCount);

                // Get the file slices.
                getSliceAsync(myFile, 0, sliceCount, gotAllSlices, docDataSlices, slicesReceived);
            } else {
                app.showNotification("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();
                app.showNotification("getSliceAsync Error:", sliceResult.error.message);
            }
    });
}

function onGotAllSlices(docDataSlices) {
    let docData = [];
    for (let i = 0; i < docDataSlices.length; i++) {
        docData = docData.concat(docDataSlices[i]);
    }

    let fileContent = new String();
    for (let 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...
}

Campos

Compressed

Retorna todo o documento (.pptx, .docx, .xlsx ou .xlsm) no formato OOXML (Office Open XML) como uma matriz de bytes.

Observação: o tipo de arquivo .xslm tem suporte no Excel no Windows e no Mac. Não há suporte em Excel na Web. No Excel no Windows, as fatias de arquivo do getFileAsync método incluem os arquivos de assinatura do VBA para tipos de arquivo .xslm. Os arquivos de assinatura do VBA são vbaProjectSignature.bin, vbaProbjectSignatureAgile.bin e vbaProjectSignatureV3.bin. No Excel no Mac, as fatias de arquivo do getFileAsync método não incluem os arquivos de assinatura do VBA, pois essa plataforma não dá suporte ao recurso de assinatura VBA.

Pdf

Retorna todo o documento no formato PDF como uma matriz de bytes.

Text

Retorna apenas o texto do documento como uma cadeia de caracteres.