简体   繁体   English

如何以编程方式在 LibreOffice Calc 中触发 AutoFit / SetOptimalHeight?

[英]How to trigger AutoFit / SetOptimalHeight in LibreOffice Calc programmatically?

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.我正在使用 unoconv 转换 XLSX => PDF。我需要 LibreOffice 来换行文本并根据 XLSX 文件的内容动态增加行高。 Is there a way to do this programmatically, maybe at the unoconv/soffice level?有没有办法以编程方式执行此操作,也许在 unoconv/soffice 级别?

The only way that worked for us was by patching unoconv so that it immediately performs the following actions after opening a document:对我们有用的唯一方法是修补 unoconv,以便它在打开文档后立即执行以下操作:

  • Select All Select 全部
  • Trigger optimal row height for the selection触发选择的最佳行高

From python, it looks like this:从 python 来看,它看起来像这样:

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补丁文件在这里: https://gist.github.com/ldiqual/065aada05cfb50443bc67fc3ae99ea14

And this is how it is applied in Docker:这就是它在 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我试图在这里解决这个问题https://github.com/PasaOpasen/_excel_correct_cells

I think results are well, but it's not so easy我认为结果很好,但并不那么容易

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM