Hi Jason,
thank you for your answer. I will try right now!
I start with an empty docx in which I just chaged the header styles.
So this is the part where I add in a loop the headers to my docx and where I try to set the bookmark with your method bookmarkRun():
- Code: Select all
P p = addParagraph(body, styleIdHeader2, newHeader);
R r =(R)p.getContent().get(0);
String bookmark = newHeader;
bookmarkRun(p, r, bookmark, ++bookmarkId);
public static P addParagraph(Body body, String styleId, String text)
{
P p = new P();
Text t = new Text();
R r = new R();
t.setValue(text);
r.getContent().add(t);
PPr pPr = factory.createPPr();
p.setPPr(pPr);
PPrBase.PStyle pStyle = factory.createPPrBasePStyle();
pPr.setPStyle(pStyle);
pStyle.setVal(styleId);
p.getContent().add(r);
body.getContent().add(p);
return p;
}
And here is the part where I create the Hyperlink in a table row:
- Code: Select all
public static Tr addHyperlinkInRow(String input)
{
Tr tableRow = factory.createTr();
Tc tableCell = factory.createTc();
P p = factory.createP();
R r = factory.createR();
Hyperlink h = MainDocumentPart.hyperlinkToBookmark(input, input);
r.getContent().add(h);
p.getContent().add(r);
tableCell.getContent().add(p);
tableRow.getContent().add(tableCell);
return tableRow;
}
And then i use this method in the part where I create my table:
- Code: Select all
tbl.getContent().add(addHyperlinkInRow(newHeader));
I can see the hyperlinks in my docx, it looks like it should, but it does not link me to the header.
Mayby you can find my mistake.