Bug 66319 - Cell.getCellComment or Cell.removeCellComment cause specific excel fail to write
Summary: Cell.getCellComment or Cell.removeCellComment cause specific excel fail to write
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: unspecified
Hardware: PC All
: P2 critical (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-10-21 16:15 UTC by nkhan
Modified: 2022-12-26 09:41 UTC (History)
0 users



Attachments
Example excel where this problem occurs (378.00 KB, application/vnd.ms-excel)
2022-10-21 16:15 UTC, nkhan
Details

Note You need to log in before you can comment on or make changes to this bug.
Description nkhan 2022-10-21 16:15:16 UTC
Created attachment 38422 [details]
Example excel where this problem occurs

I have an excel file that when iterating through and even just calling getCellComment throws an exception when I try to write it out. I have attached an example excel.

The exception is:

class org.apache.poi.hssf.record.DSFRecord cannot be cast to class org.apache.poi.hssf.record.TabIdRecord (org.apache.poi.hssf.record.DSFRecord and org.apache.poi.hssf.record.TabIdRecord are in unnamed module of loader 'app')

I am using POI 5.2.3.

Here is some code that can be used to reproduce the error:

try (FileInputStream fileInputStream = new FileInputStream(Path.of("put path to xls here").toFile());
             Workbook workbook = new HSSFWorkbook(fileInputStream)) {

            for (Sheet sheet : workbook) {
                for (Row row : sheet) {
                    for (Cell cell : row) {
                        cell.getCellComment(); // or even cell.removeCellComment();
                    }
                }
            }

            FileOutputStream fos = new FileOutputStream(Files.createTempFile("modified", ".xsl").toFile());
            workbook.write(fos);
            fos.close();
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
Comment 1 PJ Fanning 2022-12-12 21:10:36 UTC
I added r1905943 - let's see if that breaks anything else.

It doesn't fix the underlying issue as to why creating a HSSFPatriarch breaks this workbook. But there is no need to create a HSSFPatriarch in this use case.
Comment 2 Dominik Stadler 2022-12-26 09:41:54 UTC
Seems the reported issue is fixed by the changes, let's reopen or create new issues if other files cause more issues.