Bug 64707 - Editing existing XSSFTable without header corrupts xlsx
Summary: Editing existing XSSFTable without header corrupts xlsx
Status: NEEDINFO
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 4.1.x-dev
Hardware: All All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-09-03 11:39 UTC by P. K.
Modified: 2020-10-25 04:40 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description P. K. 2020-09-03 11:39:14 UTC
Editing a XSSFTable without header leads to a corrupted x

Steps to reproduce: 
1) Create a XLSX with a XSSFTable and remove / hide the header.
2) Use Apache POI to open the XLSX file and add a few lines to the table
3) Adjust the AreaReference to cover all added data
4) Write XLSX and open in Excel

The method XSSFTable.updateHeaders() always updates the table headers regardless of getHeaderRowCount().
Therefore it tries to write the first row of data into the header names.

Suggestion for a fix: XSSFTable::updateHeaders, line 821:
Extend the existing "if" with a check for getHeaderRowCount() > 0

 << if (row != null && row.getCTRow().validate()) {
 >> if (row != null && row.getCTRow().validate() && getHeaderRowCount() > 0) {
Comment 1 Dominik Stadler 2020-10-25 04:35:44 UTC
Can you provide the minimal java-code to reproduce this to be able to add a test along a fix?