Ask Your Question

Optimal column width for all tables in odt documents [closed]

asked 2013-06-08 02:27:37 +0200

Gilles gravatar image


I have existing odt files with several tables. I would like to apply optimal column width for all tables of each document. A solution working from the command line would be ideal. I tried to apply optimal column width to one of the tables and then looked into the content.xml file but it seems that there is no "optimal width" tag. It seems that the function recalculate the column width and then change that value into the xml file.

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by Alex Kemp
close date 2015-11-02 03:48:43.714275

1 Answer

Sort by » oldest newest most voted

answered 2013-06-09 13:43:00 +0200

Gilles gravatar image

updated 2013-06-09 14:00:00 +0200

I found a solution.

The following macro (found here : does the job :

Sub OptimzeColumnWidth
  Dim s As String
  Dim i As Long
  Dim oTables
  Dim oTable
  Dim oCell
  oTables = ThisComponent.getTextTables()
  If NOT oTables.hasElements() Then Exit Sub
  For i = 0 To oTables.getCount() - 1
    oTable = oTables.getByIndex(i)
    oFrame = ThisComponent.CurrentController.Frame
    oDispHelper = createUnoService("")
    oDispHelper.executeDispatch(oFrame, ".uno:SelectTable", "", 0, Array())
    oDispHelper.executeDispatch(oFrame, ".uno:SetOptimalColumnWidth", "", 0, Array()) 
End Sub

If I save the macro in a library in "my macros", I can run it from the command line like that:

libreoffice "macro:///FormatPandocOdt.Module1.OptimzeColumnWidth" myfile.odt

But I would like to have the macro saved in a library within the document (not in my macros but in myfile.odt in the macro hierarchy) and I had to do this to make it work :

libreoffice "macro://./Standard.FormatPandocOdt.OptimzeColumnWidth" myfile.odt

With my security options (middle), libroffice open and ask if I want to activate the macros within the document.

edit flag offensive delete link more


I don't know if my experience setting up a macro on the toolbar would be any help here. Thanks for posting this solution to your question, though.

David gravatar imageDavid ( 2013-06-09 14:42:32 +0200 )edit

Thanks David. For the moment It is not useful because I want to do it from outside Libreoffice. But as my report creation workflow is still in progress this may become useful eventually. So I keep it in mind...

Gilles gravatar imageGilles ( 2013-06-09 19:54:24 +0200 )edit

Question Tools


Asked: 2013-06-08 02:27:37 +0200

Seen: 764 times

Last updated: Jun 09 '13