OpenXmlPart.deleteRelationship(relationshipId)

Return to the
Open XML SDK for JavaScript
Developer Center
Removes the specified relationship from the part. Note that you must separately remove target parts.

Syntax

    part.deleteRelationship(relationshipId)

Arguments

    relationshipId: An string that contains the relationship ID of the relationship to delete.

Usage

    var rel = doc.mainDocumentPart().getRelationshipsByRelationshipType(
        openXml.relationshipTypes.wordprocessingComments);
    if (rel.length > 0) {
        doc.mainDocumentPart().deleteRelationship(rel[0].relationshipId);
    }

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."]
};