Great Andrew!!

Like i said at oooforum.org:

Nothing like to talk to the Master!
It´s works!

At the forum I put some extra code and informations.

http://www.oooforum.org/forum/viewtopic.phtml?t=21175

Best Regards and Many Thanks.
-------------------------------------------------------
André B. Derraik
Consult
Tecgraf/PUC-Rio/Brazil    http://www.tecgraf.puc-rio.br
[EMAIL PROTECTED]  Tel.: +55-21-2512-8428


Andrew Douglas Pitonyak wrote:
I added a section in my free macro documnet, if you have not already seen it, titled


     You can not move a cursor to a TextTable anchor.


This directly answers your question with a working example in Basic


Andre B Derraik wrote:

Hi,

I'm having problems with the XTextTable.
I'm trying to replace a table with a new one at the same position. Because I'm working with dynamics datas which came from Data Bases.

The table creation:

     // Get the hole Document
     XTextDocument mxDoc = getTextDocument();
     if (mxDoc == null) return;

    // Get the Factory
    XMultiServiceFactory mxDocFactory = QI.XMultiServiceFactory(mxDoc);
    if (mxDocFactory == null) return;

    // Get the Text interface
    XText mxDocText = getXText();
    if (mxDocText == null) return;

    // Get current position
    XTextRange mxDocCursor = queryCurrentPosition();
    if (mxDocCursor == null) return;

    // Create a new table from the document's factory
    XTextTable xTable = QI.XTextTable(
mxDocFactory.createInstance("com.sun.star.text.TextTable"));
    if (xTable == null) return;

   // Specify that we want the table to have 4 rows and 4 columns
   xTable.initialize(4, 4);

   // Set table name
   XNamed xNamed = QI.XNamed(xTable);
   xNamed.setName("DataTable" + id);

   // Insert the table into the document
   mxDocText.insertTextContent(mxDocCursor, xTable, false);

obs: the QI class is a sintax sugar for the UUnoRuntime.queryInterface.

at this point, works fine. He create the table perfectly.
But when I try to remove this table...

   // Get current document
   XTextDocument mxDoc = getTextDocument();
   if (mxDoc == null) return;

   // Get the Text Cursor
   XText mxDocText = mxDoc.getText();
   if (mxDocText == null) return;

   // first query the XTextTablesSupplier interface from our document
   XTextTablesSupplier xTablesSupplier = QI.XTextTablesSupplier( mxDoc );
   if (xTablesSupplier == null) return;

   // get the tables collection
   XNameAccess xNamedTables = xTablesSupplier.getTextTables();
   if (xNamedTables == null) return;

   // now query the XIndexAccess from the tables collection
   XIndexAccess xIndexedTables = QI.XIndexAccess(xNamedTables);
   if (xIndexedTables == null) return;

   // we need properties
   String name = null;

   // Find all Data tables in document
   for (int i = 0; i < xIndexedTables.getCount(); i++)
   {
      XTextTable table;
      try
      {
         // Get table name
         table = QI.XTextTable(xIndexedTables.getByIndex(i));
         if (table == null) continue;

         // check if it is an Data table
         name = QI.XNamed(table).getName();
         if (!name.startsWith("DataTable"))
                    continue;
        // Get the current table position
    XTextContent xTableContent = QI.XTextContent(table);
        XTextRange xTablePos = xTableContent.getAnchor();
        xTablePos.setString(".........\n");
    table.dispose();
      }

  }

Nothings happing!!!
The table continue exist and the new string don't appear.

Anyone, any idea?

Thanks!
Best regards.
-------------------------------------------------------
André B. Derraik
Consultor
Tecgraf/PUC-Rio           http://www.tecgraf.puc-rio.br
[EMAIL PROTECTED]  Tel.: +55-21-2512-8428

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to