This little snippet:
Target="file:///C:\Users\****\Desktop\example.xlsx"
looks like part of a relationship with an external target.
In docx/pptx/xlsx, most rel targets are internal (ie included in the pptx), but some aren't (hyperlinks - usually, images - sometimes).
docx4j handles internal and external targets differently (since generally speaking it is only for internal ones in which there is a part to load - though for external images, we do make a part).
For internal targets, you'll have a part, so you can add one using addTargetPart(Part targetpart)
For external targets, docx4j's OpcPackage has:
HashMap<ExternalTarget, Part> getExternalResources()
See
https://github.com/plutext/docx4j/blob/ ... arget.javaRelationshipsPart's getPart(Relationship r ) does, for an external target:
Using java Syntax Highlighting
return getPackage
().
getExternalResources().
get(
new ExternalTarget
( r.
getTarget() ) );
Parsed in 0.013 seconds, using
GeSHi 1.0.8.4
When a pptx is loaded, the following happens:
Using java Syntax Highlighting
// EXTERNAL
if (loadExternalTargets
&&
r.
getType().
equals( Namespaces.
IMAGE ) ) {
// It could instead be, for example, of type hyperlink,
// and we don't want to try to fetch that
log.
info("Loading external resource " + r.
getTarget()
+ " of type " + r.
getType() );
BinaryPart bp
= ExternalResourceUtils.
getExternalResource(r.
getTarget());
pkg.
getExternalResources().
put(bp.
getExternalTarget(), bp
);
} else {
log.
info("Encountered (but not loading) external resource " + r.
getTarget()
+ " of type " + r.
getType() );
}
Parsed in 0.015 seconds, using
GeSHi 1.0.8.4
It looks like that code could usefully be modified to handle the case where the pptx targets an external xlsx. Now tracking this at
https://github.com/plutext/docx4j/issues/126For your purposes though, you should be able to get the relevant Relationship object from the RelationshipsPart, and just invoke:
Using java Syntax Highlighting
public void setTarget
(String value
) {
this.
target = value
;
}
Parsed in 0.015 seconds, using
GeSHi 1.0.8.4