You can use UNO command SetOptimalColumnWidth
Sub textTableOptionalWidth
dim oDoc as object, oTable as object, document as object, dispatcher as object, oCur as object
oDoc=ThisComponent
document=oDoc.CurrentController.Frame
dispatcher=createUnoService("com.sun.star.frame.DispatchHelper")
oTable=oDoc.TextTables(0) 'your table
'oTable=oDoc.TextTables.getByName("Table1")
oCur=oTable.createCursorByCellName("A1") 'table cursor in 1st cell
oCur.goToEnd(true) 'table cursor to all cells
oDoc.CurrentController.Select(oCur) 'select table cursor
dispatcher.executeDispatch(document, ".uno:SetOptimalColumnWidth", "", 0, Array()) 'optional columns in all table
dispatcher.executeDispatch(document, ".uno:Escape", "", 0, Array()) 'deselect
End Sub