Bug 65478

Summary: DeferredSXSSFWorkboot not working cellStyle
Product: POI Reporter: silver0r <silver0r>
Component: SXSSFAssignee: POI Developers List <dev>
Status: RESOLVED INFORMATIONPROVIDED    
Severity: major    
Priority: P2    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Mac OS X 10.1   

Description silver0r 2021-07-31 09:38:22 UTC
Hello, PIO Team

I heared Apache POI 5.0.0 version upgrade and apply DeferredSXSSFWorkbook. I really wanted this and it's powerful.

When I apply DeferredSXSSFWorkbook, I found some bug.

When applying a cellStyle based on DeferredSXSSFWorkbook, it's not working and an error occurs when the excel file is opened.
(Also SXSSFWorkbook is working for me)


DeferredSXSSFWorkbook workbook = new DeferredSXSSFWorkbook(500);
DeferredSXSSFSheet deferredSXSSFSheet = workbook.createSheet();

deferredSXSSFSheet.setRowGenerator(sheet -> {
    Row row = sheet.createRow(0);
    Cell cell = row.createCell(0);
    CellStyle cellStyle = workbook.createCellStyle();
    cellStyle.setAlignment(HorizontalAlignment.RIGHT);

    cell.setCellStyle(cellStyle);
    cell.setCellValue("test");
});

workbook.write(response.getOutputStream());


Could you check it? TYSM.
Comment 1 PJ Fanning 2021-07-31 20:59:36 UTC
the row generator is designed for generating rows - can you create the style outside the row generator function?
Comment 2 silver0r 2021-08-01 05:02:59 UTC
(In reply to PJ Fanning from comment #1)
> the row generator is designed for generating rows - can you create the style
> outside the row generator function?

TYSM your comment

How can I create the cell style outside the row generator?
It would be of great help if you could provide a simple example.

and I have question. Can I make multiple row generator function in one xlsx file?

TYSM
Comment 3 PJ Fanning 2021-08-01 05:30:15 UTC
I have updated the example at https://github.com/apache/poi/blob/trunk/poi-examples/src/main/java/org/apache/poi/examples/xssf/streaming/DeferredGeneration.java to show the cell style creation. You can only add 1 row generator per sheet.
Comment 4 silver0r 2021-08-01 08:44:31 UTC
(In reply to PJ Fanning from comment #3)
> I have updated the example at
> https://github.com/apache/poi/blob/trunk/poi-examples/src/main/java/org/
> apache/poi/examples/xssf/streaming/DeferredGeneration.java to show the cell
> style creation. You can only add 1 row generator per sheet.

thanks for your kind
I'll try it :)
Comment 5 Dominik Stadler 2021-10-09 16:24:53 UTC
This is answered via an enhanced example as far as I see.