1

I have a Python script that ultimately creates a custom .xlsx file that I would then like to print when the script completes.

Throughout the process it creates a couple CSV files then organizes them and creates the .xlsx. I’ve tested a few methods and I’m able to print the CSV files pretty easily with the os.system method:

os.system(‘lpr -P name_of_printer test.csv’)

However, when I try to use the same method with my xlsx file I get the following error:

lpr: Unsupported document format

I’ve looked at multiple solutions on here, but nothing addresses the Linux issue, only Windows and MacOS. This is for a pet project so it doesn’t need to be pretty, just functional, and I need it to retain the custom formatting of the .xlsx file. Any crazy ideas or workarounds welcome. Thank you.

  • 1
    It might be easier to convert it to a pdf with libreoffice (https://askubuntu.com/questions/437331/print-xlsx-file-from-command-line-using-ghostscript-and-libreoffice), then let cups handle the pdf. – Alexander L. Hayes May 17 '21 at 22:34
  • I’ve tried going down the CUPS route, but when I call cups.Connection(), it throws a Connection() not defined error. – HoundDogSaw May 17 '21 at 22:43
  • `csv` is normal text file which you can open in any editor - and printer may treats it as text file which is simply to print. `xlsx` is compressed by zip and it has data as `xml` and it would need to render it before printing - and `lpr` may not have function for this. – furas May 17 '21 at 22:44

0 Answers0