OpenXmlPackage.deletePart(part)
Return to the
Open XML SDK for JavaScript
Developer CenterRemoves the specified part from the package. Note that you must separately remove all relationships to the part.
Syntax
openXmlDoc.deletePart(part)
Arguments
part: An OpenXmlPart object that is in the package.
Usage
var doc = new openXml.OpenXmlPackage(openXmlDocument); var commentsPart = doc.mainDocumentPart().wordprocessingCommentsPart(); doc.deletePart(commentsPart);
Example
// Open a document that is stored as Flat Opc XML. // The document contains some comments. var doc = new openXml.OpenXmlPackage(withComments_flatOpc); // Remove all references to comments. var mainPart = doc.mainDocumentPart(); var mainPartXDoc = mainPart.getXDocument(); new XEnumerable(mainPartXDoc.descendants(W.commentRangeStart)).remove(); new XEnumerable(mainPartXDoc.descendants(W.commentRangeEnd)).remove(); new XEnumerable(mainPartXDoc.descendants(W.commentReference)).remove(); // Remove the comments part. var commentsPart = mainPart.wordprocessingCommentsPart(); if (commentsPart !== null) { doc.deletePart(commentsPart); } // Remove the relationship to the comments part. var rel = doc.mainDocumentPart().getRelationshipsByRelationshipType( openXml.relationshipTypes.wordprocessingComments); if (rel.length > 0) { doc.mainDocumentPart().deleteRelationship(rel[0].relationshipId); } return { returnedDocument: doc.saveToBase64(), defaultDocumentName: "DocumentWithoutComments.docx", output: ["This example removed the comments from the document.", "Click the 'Save' button to save the modified document to a local drive. If you do not see a 'Save' button, you do not have Flash available, and can't save the document."] };