Hi All,

I have been reading through the JavaDoc and source code over the last few days to try and get an understanding of how the API works.

I have managed some good success stories, but I'm sure that I'm doing it wrong and there is a much easier way.

I am trying to add a text-sequence to a TextDocument. A simple 1,2,3.....type sequence.

That entails adding a reference to the TextSequenceDeclsElement and then outputting a TextSequence each time for it's use (within a <text:p>...</text:p> element.

Here is my code:

            td = TextDocument.newTextDocument();
            OdfContentDom contentDom = td.getContentDom();
            XPath xpath = contentDom.getXPath();
TextSequenceDeclsElement para = (TextSequenceDeclsElement) xpath.evaluate("//text:sequence-decls", contentDom, XPathConstants.NODE); TextSequenceDeclElement el = new TextSequenceDeclElement(contentDom);
            el.setTextDisplayOutlineLevelAttribute(0);
            el.setTextNameAttribute("myCounter");
            para.appendChild(el);


            int count = 0;
            TextPElement tpe = new TextPElement(contentDom);
            TextSequenceElement seq = new TextSequenceElement(contentDom);
            seq.setTextRefNameAttribute("refMyCounter" + count);
            seq.setTextFormulaAttribute("ooow:MyCounter+1");
            seq.setTextNameAttribute("MyCounter");
            seq.setStyleNumFormatAttribute("1");
            seq.newTextNode(String.valueOf(count+1));
            tpe.appendChild(seq);
            Paragraph p1 = td.addParagraph("Test");
td.insertOdfElement(p1.getOdfElement(), (Document)td, (OdfElement)tpe, true);

This works. Believe it or not. My last problem was I could add the TextSequenceElement but had to enclose it within a TextPElement in order for it to be visible. It was in the content.xml file but wasn't registering.

--
Best Regards,

Adam Parker

Reply via email to