Hello,
We’ve noticed that the draw
event from the DrawObjectEventHandler class omits empty cells. It only captures cells whose value is not null.
For example, using the attached EmptyCells.xlsx workbook, the following code illustrates the issue:
try {
final String fileName = [PATH] + "EmptyCells.xlsx";
Workbook wb = new Workbook(fileName);
// DrawObjectEventHandler
final StringBuffer drawBuffer = new StringBuffer();
drawBuffer.append("Start of DrawObjectEventHandler for ")
.append(fileName).append("\n");
DrawObjectEventHandler drawHandler = new DrawObjectEventHandler() {
@Override
public void draw(DrawObject drawObject, float x, float y, float width, float height) {
if (drawObject.getType() == DrawObjectEnum.CELL) {
Cell cell = drawObject.getCell();
drawBuffer.append("Got Cell ").append(cell.getName()).append("\n");
}
}
};
final PdfSaveOptions pdfOptions = new PdfSaveOptions();
pdfOptions.setOnePagePerSheet(false);
pdfOptions.setDrawObjectEventHandler(drawHandler);
String pdfOut = fileName.replace(".xlsx", ".pdf");
wb.save(pdfOut, pdfOptions);
System.out.println("Generated PDF file: " + pdfOut);
Path drawOut = Paths.get(fileName.replace(".xlsx", "_drawInfo.txt"));
Files.deleteIfExists(drawOut);
Files.write(drawOut, drawBuffer.toString().getBytes());
System.out.println("Generated draw output file: " + drawOut.toString());
} catch (Exception ex) {
System.out.println("Unexpected EXCEPTION: \n" + ex.getMessage());
ex.printStackTrace();
}
Running the above code produces the attached EmptyCells_drawInfo.txt file with the following text:
Start of DrawObjectEventHandler for C:\Carlos\Downloads\EmptyCells.xlsx
Got Cell A1
Got Cell C1
Got Cell E1
Got Cell F1
Got Cell A2
Got Cell B2
Got Cell C2
Got Cell E2
Got Cell A3
Got Cell C3
Got Cell F3
Got Cell A5
Got Cell B5
Got Cell C5
Got Cell E5
Got Cell F5
Got Cell F7
As you can see, all of the empty rows, columns and cells in the sheet are not included in the output.
Would it be possible to have an option for the DrawObjectEventHandler to invoke the draw
method for empty cells?
Attachment: EmptyCells.zip (6.1 KB)
Thanks