Hey Jason,
Thanks for the fast reply! I've had a bit of success creating the document part using JAXB objects, and then just unmarshalling the numbering part from a sample I had created in Word (actually, I tried creating the numbering part by hand first, but like you said, it was getting a bit tedious, and it didn't seem I could ignore the bits that I thought were unimportant
). As I'm going through this exercise, the structure of the whole thing is making a little more sense, though it just seems massive! I'll post my code below - please let me know if you have any suggestions for making things easier. I did have some larger questions though:
1 - I'm not quite sure when to use the WMLObjectFactory to create objects or when to do so via their constructor. Some don't seem to have a creation method, or at least I'm not seeing it in the list. Is there a rule of thumb as to which are done that way and which aren't?
2 - You mentioned the OpenXML spec at documentinteropinitiative.org in your other post. I may not be looking at the right thing, but I'm finding what I get through that site extremely difficult to read and use. I'm sure most of that is par for the course. Are there any guides to the format that you know of that are more grokkable?
Here's my basic bullet code:
- Code: Select all
public BasicTest() throws Docx4JException, JAXBException {
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage
.createPackage();
ObjectFactory factory = Context.getWmlObjectFactory();
NumberingDefinitionsPart numPart = new NumberingDefinitionsPart();
wordMLPackage.getMainDocumentPart().addTargetPart(numPart);
P para = factory.createP();
Text t = factory.createText();
t.setValue("This should be a bullet");
R run = factory.createR();
run.getRunContent().add(t);
para.getParagraphContent().add(run);
PPr paraProps = factory.createPPr();
para.setPPr(paraProps);
NumPr paraNum = new NumPr();
paraProps.setNumPr(paraNum);
Ilvl paraNumIlvl = new Ilvl();
paraNum.setIlvl(paraNumIlvl);
paraNumIlvl.setVal(BigInteger.ZERO);
NumId paraNumId = new NumId();
paraNum.setNumId(paraNumId);
paraNumId.setVal(BigInteger.ONE);
Body body = wordMLPackage.getMainDocumentPart().getJaxbElement()
.getBody();
body.getEGBlockLevelElts().add(para);
String numberingString = "<insert numbering section from word sample here>";
numPart.setJaxbElement((Numbering) XmlUtils
.unmarshalString(numberingString));
wordMLPackage.save(new File("BasicTestOutput.docx"));
}
... now to just combine this with the endnote sample you gave me in my other post and I'm set!
Cheers,
--Andy