Return to the
Open XML SDK for JavaScript
Developer Center
Gets an array of parts that are targets of relationships from this part, and have the specified content type. openXml.contentTypes contains a list of the most common content types.


    var parts = OpenXmlPart.getPartsByContentType(contentType);


    contentType: An string that contains the content type.

Return Value

    Returns an array of OpenXmlPart objects. If there are no parts with the specified content type, this function returns a zero length array.


    var parts = doc.mainDocumentPart()


// Open a blank document that is stored as a base64 string.
var doc = new openXml.OpenXmlPackage(blankDocument_base64);
// Get the main document part.
var mainPart = doc.mainDocumentPart();
var parts = mainPart.getPartsByContentType(openXml.contentTypes.styles);
o = ["Number of parts: " + parts.length];
for (var i = 0; i < parts.length; i++) {
    o.push("Part #" + (i + 1).toString() + " uri: " + parts[i].uri);
// Note that there are convenience functions that retrieve the most commonly used parts.
var parts2 = doc.mainDocumentPart().styleDefinitionsPart();
if (parts2 != null)
    o.push("doc.mainDocumentPart().styleDefinitionsPart() also found the style definitions part");
return { output: o };