Hi Everyone,
I successfully built a basic docker image with libreoffice installed. No GUI is available. Now i am trying to add a macro and executing it but i am not able to execute it successfully.
In particular the macro simply writes a hello world string into a tmp/text.txt file and the file does not exist. I tried several configurations for the xda files but at the end i couldnt find a working solution. It seems like the macro is not registered to to libreoffice.
Thank You
Docker file is:
-----------------
FROM ubuntu:latest
# Install LibreOffice and scripting dependencies
RUN apt-get update && apt-get install -y \
libreoffice \
libreoffice-script-provider-python \
libreoffice-script-provider-bsh \
libreoffice-script-provider-js \
&& rm -rf /var/lib/apt/lists/*
# Create necessary directories with proper permissions
RUN mkdir -p /app/.config/libreoffice/4/user/basic/Standard && \
chmod -R 777 /app/.config
# Set LibreOffice user profile path
ENV UserInstallation=file:///app/.config/libreoffice/4/user
# Create a test macro
RUN echo '<?xml version="1.0" encoding="UTF-8"?>\n\
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">\n\
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Module1" script:language="StarBasic">\n\
Sub HelloWorld\n\
Dim fileNum As Integer\n\
fileNum = FreeFile\n\
Open "/tmp/hello.txt" For Output As #fileNum\n\
Print #fileNum, "Hello, World!"\n\
Close #fileNum\n\
End Sub\n\
</script:module>' > /app/.config/libreoffice/4/user/basic/Standard/Module1.xba
# Create necessary LibreOffice configuration files
RUN echo '<?xml version="1.0" encoding="UTF-8"?>\n\
<!DOCTYPE library:library PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "library.dtd">\n\
<library:library xmlns:library="http://openoffice.org/2000/library" library:name="Standard" library:readonly="false" library:passwordprotected="false">\n\
<library:element library:name="Module1"/>\n\
</library:library>' > /app/.config/libreoffice/4/user/basic/Standard/script.xlb
RUN echo '<?xml version="1.0" encoding="UTF-8"?>\n\
<!DOCTYPE library:libraries PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "libraries.dtd">\n\
<library:libraries xmlns:library="http://openoffice.org/2000/library" xmlns:xlink="http://www.w3.org/1999/xlink">\n\
<library:library library:name="Standard" xlink:href="file:///app/.config/libreoffice/4/user/basic/Standard/script.xlb/" xlink:type="simple" library:link="false"/>\n\
</library:libraries>' > /app/.config/libreoffice/4/user/basic/script.xlc
# Set macro security settings
RUN echo '<?xml version="1.0" encoding="UTF-8"?>\n\
<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">\n\
<item oor:path="/org.openoffice.Office.Common/Security/MacroSecurity"><prop oor:name="Level" oor:op="fuse"><value>0</value></prop></item>\n\
<item oor:path="/org.openoffice.Office.Common/Security/Scripting"><prop oor:name="MacroSecurityLevel" oor:op="fuse"><value>0</value></prop></item>\n\
<item oor:path="/org.openoffice.Setup/L10N"><prop oor:name="ooLocale" oor:op="fuse"><value>en-US</value></prop></item>\n\
<item oor:path="/org.openoffice.Setup/Office"><prop oor:name="ooSetupInstCompleted" oor:op="fuse"><value>true</value></prop></item>\n\
</oor:items>' > /app/.config/libreoffice/4/user/registrymodifications.xcu
# Create a script to run the macro
RUN echo '#!/bin/bash\n\
soffice --headless --invisible \\\n\
-env:UserInstallation=file:///app/.config/libreoffice/4/user/ \\\n\
"macro:///Standard.Module1.HelloWorld"\n\
sleep 2\n\
cat /tmp/hello.txt' > /app/run_macro.sh && \
chmod +x /app/run_macro.sh
WORKDIR /app
# Set permissions
RUN chmod -R 777 /tmp
ENTRYPOINT ["/app/run_macro.sh"]
-------------------
Commads:
docker build -t libreoffice-macro-test .
docker run --rm libreoffice-macro-test
# Try with explicit user installation
soffice --headless --invisible \
-env:UserInstallation=file:///root/.config/libreoffice/4/user/ \
"macro:///Standard.Module1.HelloWorld"