OptimalWidth

Java, C++, C#, Delphi... - Using the UNO bridges
Post Reply
peter27x
Posts: 11
Joined: Thu Jan 24, 2013 3:29 pm

OptimalWidth

Post by peter27x »

Hello,

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

    oTable := DocumentOpenOffice.createInstance('com.sun.star.text.TextTable');
    oTable.initialize( NbRows + 1 , NbCols );
    Goto_BookMark(AnBkmName,ADocName);
    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 ?

Thanks.
LibreOffice 3.6.4.3 with Delphi
B Marcelly
Volunteer
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: OptimalWidth

Post by B Marcelly »

Hi,
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.
Bernard

OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
User avatar
Charlie Young
Volunteer
Posts: 1559
Joined: Fri May 14, 2010 1:07 am

Re: OptimalWidth

Post by Charlie Young »

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

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)
		oDoc.CurrentController.select(oCell)
		OptimalWidth()
	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
Post Reply