{"id":2146,"date":"2016-02-04T06:00:24","date_gmt":"2016-02-04T06:00:24","guid":{"rendered":"http:\/\/www.ericwhite.com\/home2\/bm8qcmjy\/public_html\/blog\/?page_id=2146"},"modified":"2016-02-04T06:01:00","modified_gmt":"2016-02-04T06:01:00","slug":"openxmlpart-getpartsbycontenttype","status":"publish","type":"page","link":"https:\/\/www.ericwhite.com\/blog\/openxmlpart-getpartsbycontenttype\/","title":{"rendered":"OpenXmlPart.getPartsByContentType(contentType)"},"content":{"rendered":"<p><span class=\"Back\"><a class=\"Back\" href=\"https:\/\/www.ericwhite.com\/blog\/open-xml-sdk-for-javascript\/\">Return to the<br \/>Open XML SDK for JavaScript<br \/>Developer Center<\/a><\/span>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.<\/p>\n<h1>Syntax<\/h1>\n<pre>\r\n    var parts = OpenXmlPart.getPartsByContentType(contentType);\r\n<\/pre>\n<h1>Arguments<\/h1>\n<pre>\r\n    contentType: An string that contains the content type.\r\n<\/pre>\n<h1>Return Value<\/h1>\n<pre>\r\n    Returns an array of OpenXmlPart objects. If there are no parts with the specified content type, this function returns a zero length array.\r\n<\/pre>\n<h1>Usage<\/h1>\n<pre>\r\n    var parts = doc.mainDocumentPart()\r\n        .getPartsByContentType(openXml.contentTypes.styleDefinitionsPart);\r\n<\/pre>\n<h1>Example<\/h1>\n<pre>\r\n\/\/ Open a blank document that is stored as a base64 string.\r\nvar doc = new openXml.OpenXmlPackage(blankDocument_base64);\r\n\/\/ Get the main document part.\r\nvar mainPart = doc.mainDocumentPart();\r\nvar parts = mainPart.getPartsByContentType(openXml.contentTypes.styles);\r\no = [\"Number of parts: \" + parts.length];\r\nfor (var i = 0; i < parts.length; i++) {\r\n    o.push(\"Part #\" + (i + 1).toString() + \" uri: \" + parts[i].uri);\r\n}\r\n\/\/ Note that there are convenience functions that retrieve the most commonly used parts.\r\nvar parts2 = doc.mainDocumentPart().styleDefinitionsPart();\r\nif (parts2 != null)\r\n    o.push(\"doc.mainDocumentPart().styleDefinitionsPart() also found the style definitions part\");\r\nreturn { output: o };\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Return to theOpen XML SDK for JavaScriptDeveloper CenterGets 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. Syntax var parts = OpenXmlPart.getPartsByContentType(contentType); Arguments contentType: An string that contains the content type. Return Value Returns an array [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"_s2mail":"","footnotes":""},"class_list":["post-2146","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/pages\/2146","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/comments?post=2146"}],"version-history":[{"count":2,"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/pages\/2146\/revisions"}],"predecessor-version":[{"id":2148,"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/pages\/2146\/revisions\/2148"}],"wp:attachment":[{"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/media?parent=2146"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}