[Solved] Create table with a specific name

Java, C++, C#, Delphi, ??? - Using the UNO bridges

[Solved] Create table with a specific name

Postby jacklafrip » Wed Jun 01, 2011 11:59 am

Hi all,

After some searches on this forum and in the dev guide, I do not have find the solution to my problem.
I want to specify a name to my table, so that I will be able to retrive it without problems with an other program.

I have modify the name using the following way:
Code: Select all   Expand viewCollapse view
   XTextTable xTextTable = (XTextTable)((XMultiServiceFactory)TextDocument).createInstance("com.sun.star.text.TextTable");
   xTextTable.initialize(4, 2);
   unoidl.com.sun.star.text.XTextTable xTextTable1 = (unoidl.com.sun.star.text.XTextTable)((XMultiServiceFactory)TextDocument).createInstance("com.sun.star.text.TextTable");
   xTextTable1.initialize(2, 4);

   TextDocument.getText().insertTextContent(cursor, xTextTable, false);
   TextDocument.getText().insertString(cursor, "\n", false);
   TextDocument.getText().insertTextContent(cursor, xTextTable1, false);

   XPropertySet xTableProps1 = (XPropertySet)xTextTable;
   xTableProps1.setPropertyValue("TableName",new uno.Any("NomduTableau"));


But when I open the document, the two tables have always the names : "Tableau1" and "Tableau2" (I'm using French OO).
The second should have the "NomduTableau" name, isn't it?

I do not understand the problem.

Best regards,
Last edited by Hagar Delest on Wed Jun 01, 2011 4:31 pm, edited 1 time in total.
Reason: tagged [Solved].
OpenOffice 3.3 on WindowsXP / VisualStudio 2005
jacklafrip
 
Posts: 7
Joined: Mon May 30, 2011 11:41 am

Re: Create table with a specific name

Postby RoryOF » Wed Jun 01, 2011 12:30 pm

This thread may provide some helpful information after making any appropriate changes.
http://user.services.openoffice.org/en/forum/viewtopic.php?f=20&t=31977
Apache OpenOffice 4.1.7 on Xubuntu 20.04.1 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 31414
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Create table with a specific name

Postby jacklafrip » Wed Jun 01, 2011 2:28 pm

Thank you very much.
This post solved my problem.

The code is now :
Code: Select all   Expand viewCollapse view
   XTextTable xTextTable = (XTextTable)((XMultiServiceFactory)TextDocument).createInstance("com.sun.star.text.TextTable");
   xTextTable.initialize(4, 2);
   unoidl.com.sun.star.text.XTextTable xTextTable1 = (unoidl.com.sun.star.text.XTextTable)((XMultiServiceFactory)TextDocument).createInstance("com.sun.star.text.TextTable");
   xTextTable1.initialize(2, 4);

   TextDocument.getText().insertTextContent(cursor, xTextTable, false);
   TextDocument.getText().insertString(cursor, "\n", false);
   TextDocument.getText().insertTextContent(cursor, xTextTable1, false);

   XNamed xTableNamed = (XNamed)xTextTable;
   xTableTable.setName("GoodNameOfThisTable");
// Now the first name is modified


If someone is looking for automatic name modification, the solution could be, to retrieve all tables and to rename them.
Code: Select all   Expand viewCollapse view
XTextTablesSupplier xTextTablesSupplier = (unoidl.com.sun.star.text.XTextTablesSupplier)xComponent;
// retrieve all tables
XNameAccess xNamedTables = xTextTablesSupplier.getTextTables();
XIndexAccess xIndexedTables = (XIndexAccess)xNamedTables;

int i = 0;
// get the tables
foreach (string Table in xNamedTables.getElementNames())
{
// Cast the tables to XNamed
   XNamed xNamedTable = (XNamed)xNamedTables.getByName(Table).Value;
// Modify the tables name
   tttable.setName("BaseTableName" + i.ToString());
   i++;
}


Thank you for your help !
OpenOffice 3.3 on WindowsXP / VisualStudio 2005
jacklafrip
 
Posts: 7
Joined: Mon May 30, 2011 11:41 am


Return to External Programs

Who is online

Users browsing this forum: No registered users and 2 guests