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


Postby peter27x » Thu Jan 24, 2013 5:52 pm


I have inserted a table in swriter from Delphi, I can then insert text into it, no problem for that.

The problem is for adjusting the columns automatically or not, nothing works.

I create the table like that :

Code: Select all   Expand viewCollapse view
    oTable := DocumentOpenOffice.createInstance('com.sun.star.text.TextTable');
    oTable.initialize( NbRows + 1 , NbCols );
    oCurseur := DocumentOpenOffice.getCurrentController.getViewCursor;
    oText := DocumentOpenOffice.getText;
    oText.insertTextContent( oCurseur, oTable, true );

    // first try to change the columns width : NO EFFECT
    tabSeparateur := oTable.TableColumnSeparators;
    tabSeparateur[0].Position  := 3000;
    tabSeparateur[1].Position  := tabSeparateur[1].Position + 5000;
    tabSeparateur[2].Position  := tabSeparateur[2].Position + 2000;
    tabSeparateur[3].Position  := tabSeparateur[3].Position + 2000;
    oTable.TableColumnSeparators := tabSeparateur;

    // then several tries to access columns optimalWidth property...
    // but always exception raised +/- like "no such property...   
    // hours spent on the web with no solution...

Can anyone give the working code for accessing and setting to TRUE the columns optimalWidth property ?

LibreOffice with Delphi
Posts: 11
Joined: Thu Jan 24, 2013 3:29 pm

Re: OptimalWidth

Postby B Marcelly » Thu Jan 24, 2013 9:12 pm

From the table you can use .getColumns()
This is a container of the columns. However it is not possible to access a column, see Bug 76353.
I think there is no solution to your request.
As to setting columns separator, you will find examples on the web.

OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
B Marcelly
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: OptimalWidth

Postby Charlie Young » Fri Jan 25, 2013 1:05 am

The problem is probably related to the structure of TextTables:

OpenOffice.org text tables consist of rows, rows consist of one or more cells, and cells can contain text or rows. There is no logical concept of columns. From the API's perspective, a table acts as if it had columns, as long as there are no split or merged cells.

At least if there are no split or merged cells, we can use dispatcher calls.

As I've mentioned before, I don't know Delphi and my Pascal is very rusty, but in Basic

Code: Select all   Expand viewCollapse view
Sub SetColumnWidths()
   Dim oDoc As Object
   Dim SomeTable As Object
   Dim oCell As Object
   Dim ColCount As Long
   Dim i As Long
   oDoc = ThisComponent
   SomeTable = oDoc.getTextTables().getByIndex(0)
   ColCount = SomeTable.Columns.Count
   for i = 0 to ColCount - 1
      oCell = SomeTable.getCellByPosition(i,0)
   next i
End Sub

Sub OptimalWidth()

   dim document   as object
   dim dispatcher as object
   document   = ThisComponent.CurrentController.Frame
   dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

   dispatcher.executeDispatch(document, ".uno:EntireColumn", "", 0, Array())

   dispatcher.executeDispatch(document, ".uno:SetOptimalColumnWidth", "", 0, Array())

End Sub
Apache OpenOffice 4.1.1
Windows XP
User avatar
Charlie Young
Posts: 1559
Joined: Fri May 14, 2010 1:07 am

Return to External Programs

Who is online

Users browsing this forum: No registered users and 2 guests