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 Forgot to add the link: http://www.pitonyak.org/OOME_4_0.odt On 2/8/19 8:42 AM, LORENZO Vincent wrote:
-- 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