[Solved] Create table with a specific name

Java, C++, C#, Delphi... - Using the UNO bridges
Post Reply
jacklafrip
Posts: 7
Joined: Mon May 30, 2011 11:41 am

[Solved] Create table with a specific name

Post by jacklafrip »

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

	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
User avatar
RoryOF
Moderator
Posts: 35066
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Create table with a specific name

Post by RoryOF »

This thread may provide some helpful information after making any appropriate changes.
http://user.services.openoffice.org/en/ ... 20&t=31977
Apache OpenOffice 4.1.15 on Xubuntu 22.04.5 LTS
jacklafrip
Posts: 7
Joined: Mon May 30, 2011 11:41 am

Re: Create table with a specific name

Post by jacklafrip »

Thank you very much.
This post solved my problem.

The code is now :

Code: Select all

   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

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
Post Reply