I'm using unoconv to convert XLSX => PDF. I need LibreOffice to wrap text and increase row heights dynamically depending on the contents of the XLSX file. Is there a way to do this programmatically, maybe at the unoconv/soffice level?
How to trigger AutoFit / SetOptimalHeight in LibreOffice Calc programmatically?
618 Views Asked by ldiqual At
2
There are 2 best solutions below
0

The only way that worked for us was by patching unoconv so that it immediately performs the following actions after opening a document:
- Select All
- Trigger optimal row height for the selection
From python, it looks like this:
frame = document.CurrentController.Frame
dispatcher = self.unosvcmgr.createInstanceWithContext("com.sun.star.frame.DispatchHelper", self.context)
dispatcher.executeDispatch(frame, ".uno:SelectAll", "", 0, ())
dispatcher.executeDispatch(frame, ".uno:SetOptimalRowHeight", "", 0, UnoProps(aExtraHeight=0))
The patch file is here: https://gist.github.com/ldiqual/065aada05cfb50443bc67fc3ae99ea14
And this is how it is applied in Docker:
ENV UNO_URL https://raw.githubusercontent.com/unoconv/unoconv/master/unoconv
COPY ./unoconv.patch /tmp/unoconv.patch
RUN curl -Ls ${UNO_URL} -o /usr/local/bin/unoconv \
&& patch /usr/local/bin/unoconv /tmp/unoconv.patch \
&& chmod +x /usr/local/bin/unoconv \
&& rm /tmp/unoconv.patch \
I tryed to solve this problem here https://github.com/PasaOpasen/_excel_correct_cells
I think results are well, but it's not so easy