如何在没有 GUI 的情况下从命令行运行 libreoffice 宏?

发布于 2025-01-09 14:51:16 字数 1889 浏览 0 评论 0原文

简介

我有一个带有 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(&quot;PageStyles&quot;)
    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.xlsx

奇怪的是,我可以很好地运行其他无头 libreoffice 命令。例如,如果我尝试使用 soffice --headless --nologo --nofirststartwizard --norestore --convert-to pdf --outdir 将文件转换为 pdf 而不更改缩放比例。.xlsx,然后 soffice 就可以正常运行了。

其他信息:

  • 我实例化了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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

傲娇萝莉攻 2025-01-16 14:51:16

您对宏的调用缺少斜杠 /

命令行应该以

    $ soffice --headless --nologo --nofirststartwizard --norestore macro:///Standard.Module1.FitToPage <file>.xlsx 

无头模式运行将掩盖有关运行宏的任何安全消息,只需删除 --headless 即可让您检查是否存在任何可能有关运行您需要授权的未知宏的安全消息,在 --headless 运行继续并完成之前。

Your call of the macro is missing a slash /.

The command line should be

    $ soffice --headless --nologo --nofirststartwizard --norestore macro:///Standard.Module1.FitToPage <file>.xlsx 

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文