jmcnamara / XlsxWriter

A Python module for creating Excel XLSX files.
https://xlsxwriter.readthedocs.io
BSD 2-Clause "Simplified" License
3.61k stars 630 forks source link

Bug: The file format and extension of sample.xls dont match. The file could be corrupted or unsafe. Unless you trust your source, don't open it. #1084

Closed john1jan closed 1 month ago

john1jan commented 1 month ago

Current behavior

Getting this error after generating the file with xlswriter in windows. The file format and extension of sample.xls dont match. The file could be corrupted or unsafe. Unless you trust your source, don't open it.

image

Expected behavior

No error

Sample code to reproduce

import xlsxwriter

workbook = xlsxwriter.Workbook('hello.xlsx')
worksheet = workbook.add_worksheet()

worksheet.write('A1', 'Hello world')

workbook.close()

Environment

- XlsxWriter version:
- Python version:
- Excel version:
- OS:

Any other information

No response

OpenOffice and LibreOffice users

jmcnamara commented 1 month ago

That is just a standard error/warning that Excel gives when the file extension (xls in this case)doesn't match the file format (xlsx).

The same thing happens if you rename an Excel file from xlsx to xls so it isn't an XlsxWriter issue.