Hi All!
My problem is that I want to include a link that refer to an internal embedded document, so click on it will open the document. If I set the target to an external source (like web url) it works fine: String linkId = xdoc.getPackagePart().addExternalRelationship("http://www.website.hu", XWPFRelation.HYPERLINK.getRelation()).getId(); CTHyperlink cLink = myParagraph.getCTP().addNewHyperlink(); cLink.setId(linkId); And that is it, it works fine. Now I want to accomplish the same behaviour, but this time hyperlink should point to an internal document which resides in the docx under path word/embeddings/test.docx //embedded part is the packagepart for the document String linkId = xdoc.getPackagePart().addRelationship(embeddedPart.getPartName(), TargetMode.INTERNAL, XWPFRelation.DOCUMENT.getRelation()).getId(); CTHyperlink cLink = myParagraph.getCTP().addNewHyperlink(); cLink.setId(linkId); I want to include a link that refer to an internal embedded document, so click on it will open the document. If I set the target to an external source (like web url) it works fine: String linkId = xdoc.getPackagePart().addExternalRelationship("http://www.website.hu", XWPFRelation.HYPERLINK.getRelation()).getId(); CTHyperlink cLink = myParagraph.getCTP().addNewHyperlink(); cLink.setId(linkId); And that is it, it works fine. I just created an externalrelationship with the target url and relationtype and passed it to the hyperlink. Now I want to accomplish the same behaviour, but this time hyperlink should point to an internal document which resides in the docx under path word/embeddings/test.docx //embedded part is the packagepart for the document String linkId = xdoc.getPackagePart().addRelationship(embeddedPart.getPartName(), TargetMode.INTERNAL, XWPFRelation.DOCUMENT.getRelation()).getId(); CTHyperlink cLink = myParagraph.getCTP().addNewHyperlink(); cLink.setId(linkId); And this is where dead end comes: clicking on the link (the link popup shows the correct path inside docx) automatically change to path to and external one which points to my filesystem. So if my working directory is in c:\myfile the link to my internal file inside docx 'word/embeddings/test.docx' will be changed to c:/myfile/word/embeddings/test.docx . So i am unable to force it to resolve the link as an internal one. Any Idea? So how should I refer to an internal document via hyperlinks? Thanks -- Sent from: http://apache-poi.1045710.n5.nabble.com/POI-User-f2280730.html --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
I would create a minimal Excel file containing the embedded link as
intended and then look at the files in the .xlsx (use Unzip to extract files from the .xlsx), then you can find out how the link needs to be set up to do what you want it to. Thanks... Dominik. On Sat, Jun 15, 2019 at 3:46 PM zoli <[hidden email]> wrote: > Hi All! > > My problem is that I want to include a link that refer to an internal > embedded document, so click on it will open the document. > > If I set the target to an external source (like web url) it works fine: > > String linkId = > xdoc.getPackagePart().addExternalRelationship("http://www.website.hu", > XWPFRelation.HYPERLINK.getRelation()).getId(); > CTHyperlink cLink = myParagraph.getCTP().addNewHyperlink(); > cLink.setId(linkId); > > And that is it, it works fine. > > Now I want to accomplish the same behaviour, but this time hyperlink should > point to an internal document which resides in the docx under path > word/embeddings/test.docx > > //embedded part is the packagepart for the document > String linkId = > xdoc.getPackagePart().addRelationship(embeddedPart.getPartName(), > TargetMode.INTERNAL, XWPFRelation.DOCUMENT.getRelation()).getId(); > CTHyperlink cLink = myParagraph.getCTP().addNewHyperlink(); > cLink.setId(linkId); > > > > I want to include a link that refer to an internal embedded document, so > click on it will open the document. > > If I set the target to an external source (like web url) it works fine: > > String linkId = > xdoc.getPackagePart().addExternalRelationship("http://www.website.hu", > XWPFRelation.HYPERLINK.getRelation()).getId(); > CTHyperlink cLink = myParagraph.getCTP().addNewHyperlink(); > cLink.setId(linkId); > > And that is it, it works fine. I just created an externalrelationship with > the target url and relationtype and passed it to the hyperlink. > > Now I want to accomplish the same behaviour, but this time hyperlink should > point to an internal document which resides in the docx under path > word/embeddings/test.docx > > //embedded part is the packagepart for the document > String linkId = > xdoc.getPackagePart().addRelationship(embeddedPart.getPartName(), > TargetMode.INTERNAL, XWPFRelation.DOCUMENT.getRelation()).getId(); > CTHyperlink cLink = myParagraph.getCTP().addNewHyperlink(); > cLink.setId(linkId); > > And this is where dead end comes: clicking on the link (the link popup > shows > the correct path inside docx) automatically change to path to and external > one which points to my filesystem. So if my working directory is in > c:\myfile the link to my internal file inside docx > 'word/embeddings/test.docx' will be changed to > c:/myfile/word/embeddings/test.docx . So i am unable to force it to > resolve > the link as an internal one. > > Any Idea? So how should I refer to an internal document via hyperlinks? > Thanks > > > > -- > Sent from: http://apache-poi.1045710.n5.nabble.com/POI-User-f2280730.html > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [hidden email] > For additional commands, e-mail: [hidden email] > > |
Free forum by Nabble | Edit this page |