OpenXmlPackage.saveToFlatOpc()

Return to the
Open XML SDK for JavaScript
Developer Center
Saves all parts of the document into a single XML file that is in the Flat OPC format.

Syntax

    openXmlDoc.saveToFlatOpc();

Return Value

    Returns a string that contains the Flat OPC XML that you can, for example, save to a local drive.

Usage

    var doc = new openXml.OpenXmlPackage(base64doc);
    var flatOpcString = doc.saveToFlatOpc();

Example

// This example opens a DOCX, adds some content, and saves to Flat OPC.
// Open a blank document that is stored as a base64 string.
var doc = new openXml.OpenXmlPackage(blankDocument_base64);
var para = doc.mainDocumentPart().getXDocument().descendants(W.p).firstOrDefault();
if (para !== null) {
    para.replaceWith(
        new XElement(W.p,
            new XElement(W.r,
                new XElement(W.t, "Hello, Flat OPC"))));
}
// Save the document to Flat Opc.
var flatOpcDoc = doc.saveToFlatOpc();
return {
    returnedDocument: flatOpcDoc,
    defaultDocumentName: "FlatOpc.xml",
    output: "Click the 'Save' button to save the XML to a local drive.  If you do not see a 'Save' button, you do not have Flash available, and can't save the document."
};