-1

I need to run Libreoffice --covert-to to convert an excel file to html page. The current code works well within the windows machine. But in AWS, CentOS6, it's producing an error as "Failed to open display". Here is my code

import subprocess
cwdir = '/opt/libreoffice6.2/program'
excel_path = '/home/ec2-user/PythonCode/testing/Book1.xlsx'
dest_path = '/home/ec2-user/PythonCode/testing'
html_command = ["soffice", "--headless", "--convert-to", "html", "--outdir", 
               dest_path, excel_path]
subprocess.run(html_command, shell=True, cwd=cwdir)`
paul-shuvo
  • 1,874
  • 4
  • 33
  • 37
Praveen
  • 74
  • 1
  • 12
  • The issue appears to be with LibreOffice. Are you certain you are using `soffice` from `/opt/libreoffice6.2/program`? Is it on-path? Maybe you should try `html_command = ["/opt/libreoffice6.2/programsoffice/soffice" ...]`. Also see [Bug 71064 - "Failed to open display" error in the help message when using LO via SSH](https://bugs.documentfoundation.org/show_bug.cgi?id=71064) and [Bug 121275 - LibreOffice does not start on wayland without an Xwayland DISPLAY running](https://bugs.documentfoundation.org/show_bug.cgi?id=121275). You should probably file a bug report. – jww Dec 27 '19 at 06:14
  • I changed the code to `html_command = ["/opt/libreoffice6.2/program/soffice", "--headless", "--convert-to", "html", "--outdir", dest_path, excel_path]`still getting the same error, with one more message as **/opt/libreoffice6.2/program/soffice.bin: /lib64/libdbus-1.so.3: no version information available (required by /opt/libreoffice6.2/program/libmergedlo.so)** and ** /opt/libreoffice6.2/program/soffice.bin: /lib64/libdbus-1.so.3: no version information available (required by /opt/libreoffice6.2/program/libmergedlo.so)** – Praveen Dec 27 '19 at 06:57
  • It would be better if you have commented the reason for your down vote so that I can improve it next time – Praveen Jan 13 '20 at 06:32

1 Answers1

0

I was able to convert excel file to html file with some minor changes. The values inside list is not working so I have to provide the soffice convert-to query as a string value and the folder contains the input excel file and destination folder , where the html file to be stored,must be different.

import subprocess
cwdir = '/opt/libreoffice6.2/program'
excel_path = '/home/ec2-user/PythonCode/testing/Book1.xlsx'
dest_path = '/home/ec2-user/PythonCode/testing/output'
html_command = r"soffice --headless --convert-to html --outdir " + " " + dest_path + " " + excel_path
subprocess.run(html_command, shell=True, cwd=cwdir)
Praveen
  • 74
  • 1
  • 12