Office.GetFileOptions interface

Bietet Optionen zum Festlegen der Größe der Segmente, in die das Dokument unterteilt wird.

Hinweise

Verwendet von

Beispiele

// The following example gets the document in Office Open XML ("compressed") format in 65536 bytes (64 KB) slices.
function getDocumentAsCompressed() {
    let fileOptions: Office.GetFileOptions = {
        sliceSize: 65536 /*64 KB*/
    };
    Office.context.document.getFileAsync(Office.FileType.Compressed, fileOptions,
        function (result) {
            if (result.status === Office.AsyncResultStatus.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;
                console.log("File size:" + myFile.size + " #Slices: " + sliceCount);

                // Get the file slices.
                getSliceAsync(myFile, 0, sliceCount, gotAllSlices, docDataSlices, slicesReceived);
            } else {
                console.error("Error:", result.error.message);
            }
    });
}

function getSliceAsync(file, nextSlice, sliceCount, gotAllSlices, docDataSlices, slicesReceived) {
    file.getSliceAsync(nextSlice, function (sliceResult) {
        if (sliceResult.status === Office.AsyncResultStatus.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.error("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...
}

// The following example gets the document in PDF format.
Office.context.document.getFileAsync(Office.FileType.Pdf,
    function(result) {
        if (result.status === Office.AsyncResultStatus.Succeeded) {
            const myFile = result.value;
            const sliceCount = myFile.sliceCount;
            console.log("File size:" + myFile.size + " #Slices: " + sliceCount);

            // Get the file slices.
            const docDataSlices = [];
            let slicesReceived = 0, gotAllSlices = true;
            getSliceAsync(myFile, 0, sliceCount, gotAllSlices, docDataSlices, slicesReceived);
            
            myFile.closeAsync();
        } else {
            console.error("Error:", result.error.message);
        }
    }
);

Eigenschaften

asyncContext

Ein benutzerdefiniertes Element eines beliebigen Typs, das unverändert in der asyncContext-Eigenschaft des AsyncResult-Objekts zurückgegeben wird, das an einen Rückruf übergeben wird.

sliceSize

Die Größe der Slices in Bytes. Der Höchstwert (und der Standardwert) ist 4194304 (4 MB).

Details zur Eigenschaft

asyncContext

Ein benutzerdefiniertes Element eines beliebigen Typs, das unverändert in der asyncContext-Eigenschaft des AsyncResult-Objekts zurückgegeben wird, das an einen Rückruf übergeben wird.

asyncContext?: any

Eigenschaftswert

any

sliceSize

Die Größe der Slices in Bytes. Der Höchstwert (und der Standardwert) ist 4194304 (4 MB).

sliceSize?: number

Eigenschaftswert

number