workbook.save() of python's openpyxl module is not working
Question: I was trying to open a XLSX file using openpyxl module. Following is my
script:-

    
    
    from openpyxl import load_workbook
    
    print "Going to execute the script"
    workbook = load_workbook("FileName.xlsx")
    worksheet = workbook.get_sheet_by_name("Sheet01")
    worksheet['B8'] = "Customer07"
    workbook.save("FileName.xlsx")
    print "End of script execution"
    

When I execute this script I get the following error:-

    
    
    /usr/lib/python2.6/site-packages/openpyxl-2.2.0-py2.6.egg/openpyxl/xml/__init__.py:15: UserWarning: The installed version of lxml is too old to be used with openpyxl
      warnings.warn("The installed version of lxml is too old to be used with openpyxl")
    Going to execute the script
    /usr/lib/python2.6/site-packages/openpyxl-2.2.0-py2.6.egg/openpyxl/workbook/names/named_range.py:121: UserWarning: Discarded range with reserved name
      warnings.warn("Discarded range with reserved name")
    Traceback (most recent call last):
      File "check.py", line 11, in <module>
        workbook.save("FileName.xlsx")
      File "/usr/lib/python2.6/site-packages/openpyxl-2.2.0-py2.6.egg/openpyxl/workbook/workbook.py", line 296, in save
        save_workbook(self, filename)
      File "/usr/lib/python2.6/site-packages/openpyxl-2.2.0-py2.6.egg/openpyxl/writer/excel.py", line 191, in save_workbook
        writer.save(filename, as_template=as_template)
      File "/usr/lib/python2.6/site-packages/openpyxl-2.2.0-py2.6.egg/openpyxl/writer/excel.py", line 174, in save
        self.write_data(archive, as_template=as_template)
      File "/usr/lib/python2.6/site-packages/openpyxl-2.2.0-py2.6.egg/openpyxl/writer/excel.py", line 85, in write_data
        self._write_worksheets(archive)
      File "/usr/lib/python2.6/site-packages/openpyxl-2.2.0-py2.6.egg/openpyxl/writer/excel.py", line 111, in _write_worksheets
        write_worksheet(sheet, self.workbook.shared_strings,
      File "/usr/lib/python2.6/site-packages/openpyxl-2.2.0-py2.6.egg/openpyxl/writer/worksheet.py", line 299, in write_worksheet
        xf.write(comments)
      File "/usr/lib/python2.6/contextlib.py", line 34, in __exit__
        self.gen.throw(type, value, traceback)
      File "/usr/lib/python2.6/site-packages/openpyxl-2.2.0-py2.6.egg/openpyxl/xml/xmlfile.py", line 42, in element
        yield
      File "/usr/lib/python2.6/site-packages/openpyxl-2.2.0-py2.6.egg/openpyxl/writer/worksheet.py", line 276, in write_worksheet
        hf = write_header_footer(worksheet)
      File "/usr/lib/python2.6/site-packages/openpyxl-2.2.0-py2.6.egg/openpyxl/writer/worksheet.py", line 172, in write_header_footer
        header = worksheet.header_footer.getHeader()
      File "/usr/lib/python2.6/site-packages/openpyxl-2.2.0-py2.6.egg/openpyxl/worksheet/header_footer.py", line 150, in getHeader
        t.append(self.left_header.get())
      File "/usr/lib/python2.6/site-packages/openpyxl-2.2.0-py2.6.egg/openpyxl/worksheet/header_footer.py", line 90, in get
        t.append('&%d' % self.font_size)
    TypeError: %d format: a number is required, not str
    

And after this when I open "FileName.xlsx", pop box appears with message
**"Excel found unreadable comment in 'FileName.xlsx'. Do you want recover the
contents of this workbook? If you trust the source of this workbook, click
yes"**. Regardless of whatever button I click, the workbook is empty.

If I comment the following line in script,

    
    
    workbook.save("FileName.xlsx")
    

the script runs without any error but modifications are not saved in workbook.
Please help me out with this.


Answer: Try putting worksheet['B8'].value = "Customer07" instead worksheet['B8'] =
"Customer07"

