Python xlwt creates failed excel book

I am trying to use xlwt to create an output file (in .xlsx format) with multiple tabs. My Python version number is 2.7, and I use Aptana Studio 3 as an IDE.

I used the xlwt package before, with the same environment, to accomplish the same task. He worked well. But this time it works well at first, and then suddenly the output file became faulty, which cannot be opened by MS Excel.

Here is a hint that might be helpful. My Aptana Studio 3 decides to open .xlsx in its own editor, and not start MS Excel. Although this happens before the problem, I wonder if this is related.

The file looks fine when it opens in Aptana3, but when I closed it and open it using MS Excel, a pop-up message appears: "Excel cannot open the file "output.xlsx" because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file."

Can I find out how I can overcome this? Any suggestions are welcome. Thanks.

+6
source share
1 answer

The xlwt module cannot create .xlsx files. This is a writer for .xls files.

The warning is associated with a feature in newer versions of Excel called β€œextension simplification,” which means that the file extension must match the file type.

If you change the output file extension in your program to .xls , the warning should disappear and Excel will read the file.

+10
source

All Articles