What about the following:
OPCPackage pkg = OPCPackage.open(filename);
pkg.getPart(PackagingURIHelper.createPartName("/xl/_rels/workbook.xml.rels"));
Dominik.
On Fri, Jan 9, 2015 at 12:35 PM, Chris Bamford <[email protected]>
wrote:
>
> Hi there
>
> I need to look for a relationship in the ".rels" file of the
> format-specific document, not the main package itself.
> By this I mean not in the "_rels/.rels" file in the top level but in
> (say) the "xl/_rels/workbook.xml.rels" file.
> The OPCPackage class looks promising, but so far I have only been able to
> make it work with the former file.
>
> Is there an elegant way to do this, or must I do something like:
>
> OPCPackage pkg = OPCPackage.open(filename);
>
> PackageRelationship relationship =
> pkg.getRelationshipsByType(PackageRelationshipTypes.CORE_DOCUMENT).getRelationship(0);
> PackagePart part = pkg.getPart(relationship);
> String mainEntryName = part.getPartName().getName();
> String[] parts = mainEntryName.split("/");
> String docRels = "/" + parts[1] + "/_rels/" + parts[2] + ".rels"; // e.g.
> "/xl/_rels/workbook.xml.rels"
> Pattern p = Pattern.compile(docRels);
>
> PackagePart p2 = pkg.getPartsByName(p).get(0);
>
> ...
>
>
> This seems clumsy! It also has to work for all 3 OOXML types (pptx,
> dock, xlxx).
>
> Thanks,
>
> - Chris
>
>
> Chris Bamford m: +44 7860 405292 w: www.mimecast.com Senior Developer p:
> +44 207 847 8700 Address click here
> <http://www.mimecast.com/About-us/Contact-us/>
> ------------------------------
> [image: http://www.mimecast.com]
> <https://serviceA.mimecast.com/mimecast/click?account=C1A1&code=3d0286661f7ded1d012a6a763f68f5d7>
> [image: LinkedIn]
> <https://serviceA.mimecast.com/mimecast/click?account=C1A1&code=2e0d0852331c58c0317ea89a9cc669ae>
> [image:
> YouTube]
> <https://serviceA.mimecast.com/mimecast/click?account=C1A1&code=704a83df5e431323df35710fa8b4bee8>
> [image:
> Facebook]
> <https://serviceA.mimecast.com/mimecast/click?account=C1A1&code=045fddd22dbf0ac78019fa77dd927a2c>
> [image:
> Blog]
> <https://serviceA.mimecast.com/mimecast/click?account=C1A1&code=177451b2d5c813751e36ce89faf43035>
> [image:
> Twitter]
> <https://serviceA.mimecast.com/mimecast/click?account=C1A1&code=1f5be7d1e6edde6db20e9b0ec91a6186>
>
>