OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

[java] XTextTable.getColumns().getByIndex() -> null

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
mlerutte
General User
General User


Joined: 23 Jan 2006
Posts: 6
Location: Swalmen, The Netherlands

PostPosted: Mon Jan 23, 2006 12:18 pm    Post subject: [java] XTextTable.getColumns().getByIndex() -> null Reply with quote

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
View user's profile Send private message
edv
Power User
Power User


Joined: 20 Sep 2005
Posts: 73
Location: Germany

PostPosted: Mon Jan 23, 2006 11:14 pm    Post subject: Reply with quote

Hi,

perhaps you should let us know what type your variables "columns" and "columnservice" are of.
Back to top
View user's profile Send private message
mlerutte
General User
General User


Joined: 23 Jan 2006
Posts: 6
Location: Swalmen, The Netherlands

PostPosted: Tue Jan 24, 2006 10:41 am    Post subject: Reply with quote

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
View user's profile Send private message
edv
Power User
Power User


Joined: 20 Sep 2005
Posts: 73
Location: Germany

PostPosted: Wed Jan 25, 2006 12:13 am    Post subject: Reply with quote

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
View user's profile Send private message
B Marcelly
Super User
Super User


Joined: 12 May 2004
Posts: 1453
Location: France

PostPosted: Wed Jan 25, 2006 12:40 am    Post subject: Reply with quote

You don't change a TextTable column width by its property. You must use TableColumnSeparators. See this thread
Back to top
View user's profile Send private message Visit poster's website
mlerutte
General User
General User


Joined: 23 Jan 2006
Posts: 6
Location: Swalmen, The Netherlands

PostPosted: Sun Jan 29, 2006 12:16 am    Post subject: Reply with quote

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
View user's profile Send private message
AlfonsName
General User
General User


Joined: 07 Aug 2006
Posts: 7

PostPosted: Fri Aug 18, 2006 7:28 am    Post subject: TableColumnRelativeSum Reply with quote

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
View user's profile Send private message
pitonyak
Administrator
Administrator


Joined: 09 Mar 2004
Posts: 3655
Location: Columbus, Ohio, USA

PostPosted: Fri Aug 18, 2006 9:27 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
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