I am having problems with OptimalWidth for columns in calc sheets. I found that the code Sub test() below does not work. As the column 0 gets longer the number of characters not displayed increases.
sub test()
dim colnum as integer
dim oColumns as object
dim col as object
colnum = 0
oColumns = FileList.Columns
Col = oColumns.getByIndex(colnum)
Col.OptimalWidth = True
end sub
However, if I select the longest cell ($A$0 for this example) in the column and execute the code sub autoadjustcol() below the cell and the column are the correct length
sub autoadjustcol()
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args1(0) as new com.sun.star.beans.PropertyValue
dim args2(0) as new com.sun.star.beans.PropertyValue
'the next two lines moves the focus to a cell
args1(0).Name = "ToPoint"
args1(0).Value = "$A$0
'the next two lines set the variables that are in the dialog for Optimal Width
args2(0).Name = "aExtraWidth"
args2(0).Value = 0
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args1())
dispatcher.executeDispatch(document, ".uno:SetOptimalColumnWidth", "", 0, args2())
end sub
Do I have a mistake in Sub test()?