RE: how to create and fill a table of contents ? (solved)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

thank you. I don’t reuse the script, but it gives me the name (“com.sun.star.text.ContentIndex”) of the object to instantiate to create Table Of Contents.  

I’m not yet fully satisfied of I get, but it is a good start point. Here, I wrote my code for future people who get the same problem.

 

 

       private XDocumentIndex tableOfContents = null;

       /**

       * Refresh the table of contents

       */

       public void refreshTableOfContents() {

             if (null != this.tableOfContents) {

                    this.tableOfContents.update();

             }

       }

 

       /**

       * Create the table of contents

       */

       @Override

       public void writeTableOfContents(final String tocTitle) {

 

             // TODO improve me

             // we should be able to start of not the table of contents on a new page

             // we should be able to go to the next page at the end of the table of content

             try {

 

                    XTextCursor mxDocCursor = cursor;

                    XText mxDocText = cursor.getText();

                    XMultiServiceFactory mxDocFactory = odtEditor.getXMultiServiceFactory();

 

                    // Go to the end of the document

                    mxDocCursor.gotoEnd(false);

                    // Insert a new paragraph and position the cursor in it

                    mxDocText.insertControlCharacter(mxDocCursor, ControlCharacter.PARAGRAPH_BREAK, false);

                    XParagraphCursor xParaCursor = UnoRuntime.queryInterface(XParagraphCursor.class, mxDocCursor);

                    xParaCursor.gotoPreviousParagraph(false);// TODO : it was false before

 

                                 // Create a ContentIndex and access its XPropertySet interface

                    XPropertySet xIndex = UnoRuntime.queryInterface(XPropertySet.class, mxDocFactory.createInstance("com.sun.star.text.ContentIndex"));

 

 

                    // to fill the table of contents according to the existing title

                    xIndex.setPropertyValue("CreateFromOutline", true);

 

                    xIndex.setPropertyValue("Title", tocTitle);

 

                    // Access the XTextContent interfaces of both the Index and the

                    // IndexMark

                    XTextContent xIndexContent = UnoRuntime.queryInterface(XTextContent.class, xIndex);

                    // XTextContent xEntryContent = UnoRuntime.queryInterface(XTextContent.class, xEntry);

 

                    // Insert both in the document

                    // mxDocText.insertTextContent(mxDocCursor, xEntryContent, false);

                    mxDocText.insertTextContent(mxDocCursor, xIndexContent, false);

 

                    // Get the XDocumentIndex interface of the Index

                    XDocumentIndex xDocIndex = UnoRuntime.queryInterface(XDocumentIndex.class, xIndex);

 

                    // And call its update method

                    xDocIndex.update();

 

                    tableOfContents = xDocIndex;

 

                   

                    // xParaCursor.gotoNextParagraph(true);

 

 

                    // XText xText = mxDocCursor.getText();

                    // xText.insertControlCharacter(mxDocCursor, (short)BreakType.PAGE_AFTER_value, false);

                    // mxDocCursor.gotoEnd(false);

                    // WriteUtil.addControlCharacter(xTextCursor, controlCharacter);addControlCharacter

 

                    XPropertySet cursorProperty = UnoRuntime.queryInterface(XPropertySet.class, xParaCursor);

                    try {

                           // TODO

                           cursorProperty.setPropertyValue("BreakType", BreakType.PAGE_BEFORE); //$NON-NLS-1$ //NONE AND BOTH gave me the same result... -> it is not good

                           // BEFORE Allow that the next content (an image) will be on the next page... it seems me stupid...

                    } catch (Exception excp) {

                           System.err.println("Failed to create page break. Exception: " + excp); //$NON-NLS-1$

                           excp.printStackTrace(System.err);

                    }

                    //

             } catch (Exception e) {

                    // TODO Auto-generated catch block

                    e.printStackTrace();

             }

       }

 

Regards,

--

Vincent Lorenzo

 

 

 

De : LibreOffice [mailto:libreoffice-bounces@xxxxxxxxxxxxxxxxxxxxx] De la part de Andrew Douglas Pitonyak
Envoyé : samedi 9 février 2019 14:25
À : libreoffice@xxxxxxxxxxxxxxxxxxxxx
Objet : Re: how to create and fill a table of contents ?

 

Forgot to add the link:

 

http://www.pitonyak.org/OOME_4_0.odt

 

On 2/8/19 8:42 AM, LORENZO Vincent wrote:

Hello,

                I’m looking for a code example to create a table of contents and fill it programmatically. I thought find something like an object called XTableOfContents  in the unoil library, but nothing and Google didn’t really help me.

So, please if you some pointers, code examples, or advices they will be welcome.

 

Best Regards,

--

Vincent LORENZO

01-69-08-17-24

CEA Saclay Nano-INNOV

Institut CARNOT CEA LIST

Point Courrier n° 174

91 191 Gif sur Yvette CEDEX

 



_______________________________________________
LibreOffice mailing list
LibreOffice@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/libreoffice
-- 
Andrew Pitonyak
My Macro Document: http://www.pitonyak.org/AndrewMacro.odt
Info:  http://www.pitonyak.org/oo.php
_______________________________________________
LibreOffice mailing list
LibreOffice@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/libreoffice

[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux