Corrupted output file when adding a table with "header_row: True" and no data
See original GitHub issueI am using XlsxWriter to create tables with a header row and data underneath. Sometimes my script has no data so there is only one row which is the header row. In that case, the generated file is corrupted according to Excel.
I am using Python version 3.7.3 and XlsxWriter 1.2.8 and Excel version 2016.
Here is some code that demonstrates the problem:
#!/usr/bin/env python3
import xlsxwriter
workbook = xlsxwriter.Workbook("test.xlsx")
worksheet = workbook.add_worksheet()
data = []
worksheet.add_table(first_row=0, first_col=0,
last_row=len(data), last_col=1,
options={
'columns': [{'header': 'test1'}, {'header': 'test2'}],
'data': data,
'header_row': True
})
workbook.close()
I know that the error is on my side but IMO xlsxwriter should catch such case and trigger an error.
Actually here is how Excel handles this:
- Create new file
- A1=“test 1” and B1="test 2
- Select A1 and B1
- Insert table and check “my table as headers”
- Notice that the table now covers two rows (so one empty data row was added)
So xlsxwriter could try to fix it in the same spirit, for example:
if len(data)==0 and last_row==0 and options['header_row']:
last_row=1
Which adds an empty data row and generates a valid file.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Apache POI createTable generates corrupted file when a ...
This is an inaccuracy with XSSFTable.updateHeaders. This method gets called while the table's XML gets written. This is because the table ...
Read more >Tidy a comma separated value (CSV) file - R
Tidies up a Comma Separated Value (CSV) file, ensuring that each row of the table in the file contains the same number of...
Read more >jmlondon/wcUtils source: R/fixCSV.R - Rdrr.io
Function fixCSV ## ##' Tidies up a Comma Separated Value (CSV) file, ensuring that each ##' row of the table in the file...
Read more >IO tools (text, CSV, HDF5, …) — pandas 1.5.2 documentation
If file contains no header row, then you should explicitly pass header=None . ... and warn_bad_lines is True , a warning for each...
Read more >Integration Services Error and Message Reference
Hexadecimal code Decimal Code Symbolic Name
0x8002F347 ‑2147290297 DTS_E_STOREDPROCSTASK_OVERWRITINGSPATD...
0x8020837E ‑2145352834 DTS_E_ADOSRCUNKNOWNTYPEMAPPEDTONTEXT
0x8020838C ‑2145352820 DTS_E_XMLSRCSCHEMACOLUMNNOTINEXTERNAL...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Fixed on master. The module now issues a warning for tables without space for data rows. The header row, or lack of one, is taken into account. Thanks for the report.
Ok. Thanks. I’ll handle them separately.
In general XlxsWriter doesn’t try to fix input issue for the user. This will probably be fixed with a warning.