Page 1 of 1

Set optimal width by C#

Posted: Sat May 07, 2022 10:31 am
by winchell
Hi i am developing with libre calc.
I want to set optimal width automitically.
I recorded the macro.
It's like blow:

Code: Select all

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

Code: Select all

dispatcher.executeDispatch(document, ".uno:SetOptimalColumnWidth", "", 0, Array())
But it didnt work with set property for SetOptimalColumnWidthDirect.

Can anyone help me on this one?

Re: How to set optimal width programmingly by C#

Posted: Sat May 07, 2022 11:31 am
by John_Ha
IIRC I once recorded a macro to set View > Optimal width ..., and used Events to run the macro each time Writer opened a document. Does the same work in Calc?

Re: How to set optimal width programmingly by C#

Posted: Sat May 07, 2022 2:08 pm
by JeJe
What do you mean it didn't work?

SetOptimalColumnWidthDirect looks to always use the default value for the added width and ignore the aExtraWidth property value. As does this method:

Code: Select all

thiscomponent.sheets(0).columns(0).optimalwidth = true
(note just looked at this in OO not LO)

Re: How to set optimal width programmingly by C#

Posted: Sat May 07, 2022 3:07 pm
by karolus
Just assign the following one-line-python to (→Rightclick Sheettab → Events →Content changed ):

Code: Select all

def optimal_width(event):
    event.Columns.OptimalWidth = True