I'm using Apache POI 3.12
(SXSSF
workbook) in order to generate .xlsx
files.
The problem is that I'm doing the generation and when I open the file I'm receiving an error message:
Excel found unreadable content in file.xlsx. Do you want to recover the contents of this workbook? If you trust the source of this workbook, click Yes.
After clicking Yes
, the file opens and I'm receiving this notification
Excel completed file level validation and repair. Some parts of this workbook may have been repaired or discarded. Removed Records: Comments from /xl/comments1.xml part (Comments) Repaired Records: Comments from /xl/comments1.xml part (Comments)
After that, I unzip the excel file and check the comments1.xml
. All my comments are present. All 216 of them.
The section of the code that generates the comments is the following
String comment = _propertiesHolder.getComment();
String commentAuthor = _propertiesHolder.getCommentAuthor();
if(comment != null)
{
int colIndex = cell.getColumnIndex();
int rowIndex = cell.getRowIndex();
CreationHelper helper = _workbook.getCreationHelper();
ClientAnchor anchor = helper.createClientAnchor();
anchor.setCol1(colIndex);
anchor.setCol2(colIndex + 1);
anchor.setRow1(rowIndex);
anchor.setRow2(rowIndex + 3);
// Create the comment and set the text+author
Comment cellComment = _drawingPatriarch.createCellComment(anchor);
if(commentAuthor != null)
{
cellComment.setAuthor(commentAuthor);
RichTextString rs = helper.createRichTextString(commentAuthor + ": " + comment);
cellComment.setString(rs);
}
else
{
cellComment.setString(helper.createRichTextString(comment));
}
cellComment.setRow(rowIndex);
cellComment.setColumn(colIndex);
// Assign the comment to the cell
cell.setCellComment(cellComment);
}
Do you have any idea what could be the cause of this problem? Although no information was lost, clearly there is something wrong and I would like to fix it. The comments are retrieved from database (varchar
datatype). The biggest comment is 138 characters long.
Update
Something that I forgot to mention. I've also run the same extraction using hssf
implementation and no errors were present. It would be a safe assumption that the data are not the problem.