| View previous topic :: View next topic |
| Author |
Message |
mlerutte General User

Joined: 23 Jan 2006 Posts: 6 Location: Swalmen, The Netherlands
|
Posted: Mon Jan 23, 2006 12:18 pm Post subject: [java] XTextTable.getColumns().getByIndex() -> null |
|
|
I'm a newbie to the OpenOffice API and after reading through the developer's guide this weekend I thought at making a shot using it from Java.
I am able to create a text table and fill it with data, but I want to set the column with. I understand that I should set the 'Width' property of a TableColumn.
I do the following:
| Code: |
tableService = createService("com.sun.star.text.TextTable");
table = queryInterface(XTextTable.class,tableService);
table.initialize(dataRows + 1,captions.length);
this.text.insertTextContent(this.cursor, table, false);
.... insert data....
columns = table.getColumns();
columnService = columns.getByIndex(0); //!!!!!!!!!!!!!!! ----> 'null'!!!!!!!!!!!!!!!!
properties = queryInterface(XPropertySet.class,columnService);
properties.setPropertyValue("Width", 100 * 1000 * 2); // 2 cm
|
Whatever column I specify in columns.getByIndex() it is always null. The columns.getCount() returns 3.
What am I doing wrong and what in the API could have triggered me?
Maurice le Rutte
Last edited by mlerutte on Sun Jan 29, 2006 12:16 am; edited 1 time in total |
|
| Back to top |
|
 |
edv Power User

Joined: 20 Sep 2005 Posts: 73 Location: Germany
|
Posted: Mon Jan 23, 2006 11:14 pm Post subject: |
|
|
Hi,
perhaps you should let us know what type your variables "columns" and "columnservice" are of. |
|
| Back to top |
|
 |
mlerutte General User

Joined: 23 Jan 2006 Posts: 6 Location: Swalmen, The Netherlands
|
Posted: Tue Jan 24, 2006 10:41 am Post subject: |
|
|
This is my, somewhat hacked-for-debugging code.
| Code: |
private void reportBacklogItems(List<PBI> pbis) throws java.lang.Exception {
if (pbis.isEmpty() == false) {
int row = 2;
Object tableService,columnService;
XTextTable textTable;
XTableColumns columns;
XCell cell;
XPropertySet properties;
this.text.insertString(this.cursor,"\n",false);
tableService = createService("com.sun.star.text.TextTable");
textTable = queryInterface(XTextTable.class,tableService);
textTable.initialize(pbis.size()+1,3);
int column = 0;
//insert the table
this.text.insertTextContent(this.cursor, textTable, false);
for(String caption : new String[] {"Backlog Item","Done?","Effort"}) {
this.setCellText(textTable, column++, 1, "%s", caption);
}
row = 2;
for(PBI pbi : pbis) {
column = 0;
this.setCellText(textTable, column++,row,"%s",pbi.getTitle());
this.setCellText(textTable, column++, row, "%s", pbi.isDone() ? "Yes" : "No");
this.setCellValue(textTable, column++, row, pbi.getCurrentEffort());
row++;
}
// cell = this.getCell(textTable, 2, row);
// cell.setFormula("sum <C2:C" + (row-1) + ">");
columns = textTable.getColumns();
for (int i = 0 ; i < columns.getCount(); i++) {
columnService = columns.getByIndex(i);
System.out.printf("Columns:%d/%d %s%n", i, columns.getCount(),columnService);
}
//properties = queryInterface(XPropertySet.class,columnService);
//properties.setPropertyValue("Width", 100 * 1000 * 2);
}
|
|
|
| Back to top |
|
 |
edv Power User

Joined: 20 Sep 2005 Posts: 73 Location: Germany
|
Posted: Wed Jan 25, 2006 12:13 am Post subject: |
|
|
OK, seems to be alright. I had the same problem, and was also not able to execute .getByIndex() properly. Maybe anybody else managed to do so?
What I am able to is to get the single cells of a TextTable:
XCell Cell=texttable.getCellByName("A1");
But probably this won`t solve your problem.....So anybody else has to help us with that, I guess |
|
| Back to top |
|
 |
B Marcelly Super User

Joined: 12 May 2004 Posts: 1414 Location: France
|
Posted: Wed Jan 25, 2006 12:40 am Post subject: |
|
|
| You don't change a TextTable column width by its property. You must use TableColumnSeparators. See this thread |
|
| Back to top |
|
 |
mlerutte General User

Joined: 23 Jan 2006 Posts: 6 Location: Swalmen, The Netherlands
|
Posted: Sun Jan 29, 2006 12:16 am Post subject: |
|
|
Yes, that works indeed. I did not understand how the width of the TableColumnSeparator works until I found the TableColumnRelativeSum property.
I still don't know what could have triggered me. That is a problem I have more in the API. For example, setting a userfield as a date requires to set the number of days since the reference date Dec. 30, 1899, while there is a Date object in the API.... |
|
| Back to top |
|
 |
AlfonsName General User

Joined: 07 Aug 2006 Posts: 7
|
Posted: Fri Aug 18, 2006 7:28 am Post subject: TableColumnRelativeSum |
|
|
| mlerutte wrote: | | Yes, that works indeed. I did not understand how the width of the TableColumnSeparator works until I found the TableColumnRelativeSum property. ... |
very good hint! |
|
| Back to top |
|
 |
pitonyak Administrator


Joined: 09 Mar 2004 Posts: 3618 Location: Columbus, Ohio, USA
|
Posted: Fri Aug 18, 2006 9:27 am Post subject: |
|
|
I think that I have an example of setting column widths in my free macro document... _________________ --
Andrew Pitonyak
http://www.pitonyak.org/oo.php |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|