I needed to export to an Excel file, so I decided to start by creating a new empty Excel file using openpyxl, but I can't save it.

import openpyxl
if __name__ == "__main__":
    book = openpyxl.Workbook ()
    book.save ("test.xlsx")

Just open and close

Traceback (most recent call last):
  File "/home/mochi/workspace/python/excel/test.py", line 6, in<module>
    book.save ("test.xlsx")
  File "/home/mochi/.local/lib/python3.6/site-packages/openpyxl/workbook/workbook.py", line 408, in save
    save_workbook (self, filename)
  File "/home/mochi/.local/lib/python3.6/site-packages/openpyxl/writer/excel.py", line 293, in save_workbook
    writer.save ()
  File "/home/mochi/.local/lib/python3.6/site-packages/openpyxl/writer/excel.py", line 275, in save
    self.write_data ()
  File "/home/mochi/.local/lib/python3.6/site-packages/openpyxl/writer/excel.py", line 75, in write_data
    self._write_worksheets ()
  File "/home/mochi/.local/lib/python3.6/site-packages/openpyxl/writer/excel.py", line 215, in _write_worksheets
    self.write_worksheet (ws)
  File "/home/mochi/.local/lib/python3.6/site-packages/openpyxl/writer/excel.py", line 200, in write_worksheet
    writer.write ()
  File "/home/mochi/.local/lib/python3.6/site-packages/openpyxl/worksheet/_writer.py", line 354, in write
    self.write_top ()
  File "/home/mochi/.local/lib/python3.6/site-packages/openpyxl/worksheet/_writer.py", line 98, in write_top
    self.write_properties ()
  File "/home/mochi/.local/lib/python3.6/site-packages/openpyxl/worksheet/_writer.py", line 60, in write_properties
    self.xf.send (props.to_tree ())
  File "/home/mochi/.local/lib/python3.6/site-packages/openpyxl/worksheet/_writer.py", line 294, in get_stream
    xf.write (el)
  File "src/lxml/serializer.pxi", line 1652, in lxml.etree._IncrementalFileWriter.write
TypeError: got invalid input value of type<class 'xml.etree.ElementTree.Element'>, expected string or Element

Error will occur.

The type is said to be different, but"test.xlsx"is a str type, so I think there should be no problem.

I thought it was a character code problem, but I'm working with UTF-8, and other file exports (json, etc.) don't have errors, so isn't it compatible with Ubuntu?

Thank you


Ubuntu 18.04 LTS
Python 3.6.8
openpyxl 3.0.2