Page 1 of 1

Warning while opening the docx document ,if we generate TOC

PostPosted: Mon Oct 22, 2012 9:29 pm
by siva kumar
"the document contains fields that may refer to other files . Do you want to update"

This is the warning pop-up i`m getting while generating TABLE OF CONTENTS with below code ..

ObjectFactory factory = Context.getWmlObjectFactory();

P p = factory.createP();
R r = factory.createR();

FldChar fldchar = factory.createFldChar();
fldchar.setFldCharType(STFldCharType.BEGIN);
fldchar.setDirty(true);
r.getRunContent().add(getWrappedFldChar(fldchar));
p.getParagraphContent().add(r);

R r1 = factory.createR();
Text txt = new Text();
txt.setSpace("preserve");
txt.setValue("TOC \\o \"1-3\" \\h \\z \\u \\h");
r.getRunContent().add(factory.createRInstrText(txt) );
p.getParagraphContent().add(r1);

FldChar fldcharend = factory.createFldChar();
fldcharend.setFldCharType(STFldCharType.END);
R r2 = factory.createR();
r2.getRunContent().add(getWrappedFldChar(fldcharend));
p.getParagraphContent().add(r2);

WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();

org.docx4j.wml.Document wmlDocumentEl = (org.docx4j.wml.Document)documentPart.getJaxbElement();
Body body = wmlDocumentEl.getBody();
body.getEGBlockLevelElts().add(p);

documentPart.addStyledParagraphOfText("Heading1", "Hello 1");
documentPart.addStyledParagraphOfText("Heading2", "Hello 2");
documentPart.addStyledParagraphOfText("Heading3", "Hello 3");
documentPart.addStyledParagraphOfText("Heading1", "Hello 1");

wordMLPackage.save(new File("c:\\AddTOC.docx"));



Thanx In Advance ,
Siva Kumar

Re: Warning while opening the docx document ,if we generate

PostPosted: Tue Oct 23, 2012 12:24 am
by jason

Re: Warning while opening the docx document ,if we generate

PostPosted: Fri Oct 26, 2012 10:42 pm
by siva kumar
Hi jason,
Thanks for the reply .
Is there any solution through docx4j api where we can aviod that warning ?
crtl+f9 is manual option and we dont want to use macros as well

Thanks in advance,
Siva Kumar