Page 1 of 1

[Duplicate] Run autofit row height from command line

Posted: Tue Mar 28, 2023 5:36 pm
by acetonic
Hello! Is it possible to run OpenOffice Calc in headless mode and run autofit command (.uno:SetOptimalRowHeight) for all cells on worksheet via command line ?

Re: Run autofit row height from command line

Posted: Sun Apr 02, 2023 10:21 pm
by MrProgrammer
acetonic wrote: Tue Mar 28, 2023 5:36 pm Is it possible to run OpenOffice Calc in headless mode and run autofit command (.uno:SetOptimalRowHeight) for all cells on worksheet via command line ?
You can record a macro to perform:
• Select → All
• Format → Row → Optional Height → OK
• File → Save

If the macro is called Foo in module Tests in library Standard of My Macros you can execute the macro with:
YourPath/soffice --headless --nofirststartwizard --norestore "YourFile.ods" "macro:///Standard.Tests.Foo()"


But it's not possible to record File → Close so the file stays open after it's saved and the soffice command never finishes. If you understand how to write macros (programming) perhaps you could edit the recorded macro and add commands to close the file. From what I recall, having the macro terminate OpenOffice may be difficult since it's OpenOffice that's running the macro. I can't help further with closing the file or with terminating OpenOffice except to suggest that if you wait a sufficient amount of time the file will have been saved and you can just kill the OpenOffice process. For many files you can use a loop:

For each file do
   Run Macro
   Wait a while
   Kill process
Done

You can probably find more additional information about steps for closing and/or terminating in Andrew Pitonyak's OpenOffice Macro Information.

Re: Run autofit row height from command line

Posted: Thu Apr 13, 2023 9:21 am
by acetonic
So, if you haven't UI on server, how can you write macros there ?

Re: Run autofit row height from command line

Posted: Thu Apr 13, 2023 3:07 pm
by MrProgrammer
acetonic wrote: Thu Apr 13, 2023 9:21 am So, if you haven't UI on server, how can you write macros there ?
Record (or write) and test macros on a system which does have a UI and transfer them to the server which doesn't. Macros in My Macros are stored in user profile folder 4 → user → basic. You must also transfer the files ending in xlb (Library Basic) and xlc (Library Container).

Your topic is a duplicate of Autofit row height in XLS files from Node.js application and has been locked. Continue any discussion there.

If this solved your problem please go to your first post use the Edit button and add [Solved] to the start of the Subject field. Select the green checkmark icon at the same time.