
Fixing BadZipFile When Reading an XLSX With Python
Fix zipfile.BadZipFile File is not a zip file when openpyxl or pandas reads an xlsx: wrong content, empty or truncated file, encryption and upload mistakes.
Where the business keeps its data. Reading workbooks, taming dates and formulas, and moving sheets to and from a database.

Fix zipfile.BadZipFile File is not a zip file when openpyxl or pandas reads an xlsx: wrong content, empty or truncated file, encryption and upload mistakes.

Fix XLRDError Excel xlsx file not supported in pandas and Python: xlrd 2 reads only old xls files, so install openpyxl and pick the right engine.

Recover data from an Excel file that will not open: test the zip, try Open and Repair, extract sheet XML by hand and read what is left with Python.

Fix the Excel message about finding a problem with some content after a script export, with the usual causes, how to read the repair log and how to bisect.

Excel says the file format or extension is not valid when the content does not match the extension. Identify the real format from its first bytes and fix it.

What #REF!, #NAME? and #VALUE! mean when a script writes the formulas, with the usual causes, how to find the cell and the fixes in openpyxl and Excel.

A map of Excel errors seen when scripts write or read workbooks: file and format messages, cell error codes, library exceptions and a debugging order.

Fix field name is not valid, reference is not valid, fields that vanish after refresh, old items that stay, lost formatting and new rows that never appear.

A docx or xlsx is a zip of XML files. Open it with zipfile, read the paragraphs, runs and tables of a docx and the shared strings and cells of an xlsx.

Show values as percent of total in an Excel pivot, then write the same share in SQL with SUM OVER and avoid integer division and rounding traps.

Turn a wide Excel sheet with a column per month into a long table: LATERAL VALUES in PostgreSQL, UNPIVOT or CROSS APPLY in SQL Server, UNION ALL in MySQL.

Pivot in MySQL with SUM and CASE, and in SQL Server with the PIVOT operator. Includes dynamic column lists built with prepared statements and QUOTENAME.
We send one email when a new article is published. No spam.