我想使用以下docker文件在Linux上执行由Docker创建的宏文件。
from ubuntu:22.04
run apt-get update \
&& apt-get -y install --no-install-recommends \
default-jre \
libreoffice-calc libreoffice-java-common \
git \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
run libreoffice --headless --terminate_after_init
我想运行以下命令将宏应用于 xlsx 文件。
虽然类似的代码在 Windows 中有效,但在 docker 中无效。shell
只是暂停并且不执行任何操作。
cp ./Module1.xba ~/.config/libreoffice/4/user/basic/Standard/
soffice --nolockcheck --nologo --headless --norestore --language=ja --nofirststartwizard ./docs/test.xlsx "macro:///Standard.Module1.Main?language=Basic&location=application"
模块1.xba
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<!--
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
-->
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Module1" script:language="StarBasic">REM ***** BASIC *****
Sub Main
ThisComponent.calculateAll()
ThisComponent.store()
ThisComponent.close(True)
StarDesktop.terminate()
End Sub
</script:module>
那么,我需要安装额外的软件包或者进行配置吗?
答案1
~/.config/libreoffice/4/user/basic/Standard/registrymodifications.xcu
这个问题是由于默认宏安全导致的。而Linux 中的LibreOffice 常规设置是这样的。
因此,我将以下代码粘贴到设置文件中。
<?xml version="1.0" encoding="UTF-8"?>
<oor:items xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<item oor:path="/org.openoffice.Setup/L10N"><prop oor:name="ooLocale" oor:op="fuse"><value>en-US</value></prop></item>
<item oor:path="/org.openoffice.Setup/Office"><prop oor:name="ooSetupInstCompleted" oor:op="fuse"><value>true</value></prop></item>
<item oor:path="/org.openoffice.Office.Common/Security/Scripting"><prop oor:name="MacroSecurityLevel" oor:op="fuse"><value>0</value></prop></item>
</oor:items>