如何在没有 GUI 的情况下从命令行运行 libreoffice 宏?
简介
我有一个带有 GUI 的 docker 容器,我在其中通过 LibreOffice Calc 注册了我的宏。使用 docker 容器提供的 GUI,我可以通过命令行成功运行宏。然而,当我将图像加载到 Kubernetes Pod 中时,当我尝试运行宏时,它会无限期地挂起。
这是宏:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Module1" script:language="StarBasic">REM ***** BASIC *****
Sub FitToPage
Dim document As Object, pageStyles As Object
document = ThisComponent
pageStyles = document.StyleFamilies.getByName("PageStyles")
For i = 0 To Document.Sheets.Count - 1
Dim sheet As Object, Style As Object
sheet = document.Sheets(i)
style = pageStyles.getByName(sheet.PageStyle)
style.ScaleToPagesX = 1
style.ScaleToPagesY = 999
Next
On Error Resume Next
document.storeSelf(Array())
document.close(true)
End Sub
</script:module>
运行宏的命令:
soffice --headless --nologo --nofirststartwizard --norestore macro://Standard.Module1.FitToPage
奇怪的是,我可以很好地运行其他无头 libreoffice 命令。例如,如果我尝试使用 soffice --headless --nologo --nofirststartwizard --norestore --convert-to pdf --outdir 将文件转换为 pdf 而不更改缩放比例。
其他信息:
- 我实例化了Ubuntu 18.04
- ,并以 root 身份运行 libre。
- 该模块是通过 LibreOffice Calc 加载的。
- 该模块可以在
~/.config/libreoffice/4/user/basic/Standard/Module1.xba
中找到。 - 我有其他 pod 在集群中运行得很好,
- 我没有为集群中的 docker 映像配置 GUI,
- 我正在将资源转储到其中(
15Gi mem,15 CPU
)
结论
任何帮助都将是非常感谢。我可以根据要求提供所需的更多信息。
更新
对我来说,在运行宏之前运行 soffice & 来在后台运行它似乎是可行的。这可能与 libreoffice 如何处理其状态有关?
无论如何,这都不是一个完美的解决方案,所以我将保留它,以防有人有更好的解决方案。
Introduction
I have a docker container with a GUI in which I registered my macro through LibreOffice Calc. Using the GUI given by the docker container, I can successfully run the macro via the command line. When I load the image in a Kubernetes Pod, however, the macro hangs indefinitely when I try to run it.
Here is the macro:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Module1" script:language="StarBasic">REM ***** BASIC *****
Sub FitToPage
Dim document As Object, pageStyles As Object
document = ThisComponent
pageStyles = document.StyleFamilies.getByName("PageStyles")
For i = 0 To Document.Sheets.Count - 1
Dim sheet As Object, Style As Object
sheet = document.Sheets(i)
style = pageStyles.getByName(sheet.PageStyle)
style.ScaleToPagesX = 1
style.ScaleToPagesY = 999
Next
On Error Resume Next
document.storeSelf(Array())
document.close(true)
End Sub
</script:module>
Command to run macro:
soffice --headless --nologo --nofirststartwizard --norestore macro://Standard.Module1.FitToPage <file>.xlsx
The strange thing is, I am able to run other headless libreoffice commands just fine. For example, if I were to try to just convert the file to a pdf without changing the scaling using soffice --headless --nologo --nofirststartwizard --norestore --convert-to pdf --outdir . <file>.xlsx
, then soffice runs perfectly fine.
Other Information:
- Ubuntu 18.04
- I instantiated and am running libre as root.
- The module was loaded in via LibreOffice Calc.
- The module can be found at
~/.config/libreoffice/4/user/basic/Standard/Module1.xba
. - I have other pods running in the cluster just fine
- I have not configured the GUI for the docker image in the cluster
- I am dumping resources into it (
15Gi mem, 15 CPU
)
Conclusion
Any help at all would be much appreciated. I can provide any more information required upon request.
UPDATE
For me, running soffice &
to run it in the background before running the macro seemed to work. It might have something to do with how libreoffice handles its state?
This isn't a perfect solution by any means, so I'm going to leave it open in case someone has a better solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您对宏的调用缺少斜杠
/
。命令行应该以
无头模式运行将掩盖有关运行宏的任何安全消息,只需删除
--headless
即可让您检查是否存在任何可能有关运行您需要授权的未知宏的安全消息,在--headless
运行继续并完成之前。Your call of the macro is missing a slash
/
.The command line should be
Running in headless mode will obscure any security messages about running macros, simply removing
--headless
allows you to check if there are any security messages possibly about running unknown macros that you need to authorsise, before a--headless
run will proceed and complete.