Created attachment 27399 [details] Test Class for the GroupRow Issue Using the groupRow method on an SXSSFSheet causes Excel to say it contains unreadable data when opening the workbook. The rows that were grouped were still active in the sliding window.
We tried to debug the issue and the issue is in groupRow() method of XSSFSheet object (_sh) in SXSSFSheet. SXSSFSheet.groupRow() calls XSSFSheet.groupRow() method. This method checks if the row exists already, if yes, then create a new row. For some reasons _rows map is empty in XSSFSheet , whereas _rows in SXSSFSheet is populated. So XSSFSheet.groupRow() method overwrites the content by creating a new Row for the same index. In short, SXSSFSheet._rows and XSSFSheet._rows are not in sync and so the rows are corrupted.
It would seem that groupRow will need to be directly implemented on SXSSFSheet, and isn't something that can be delegated down to XSSFSheet Someone would need to look at the method on XSSFSheet, review the actions it performs, then add a similar thing to SXSSFSheet (working on the sometimes different objects that SXSSF has to hand)
Support for grouping rows in SXSSF has been committed in r1295058 Please note that the rows being grouped must be in the memory window, you cannot write 1000000 rows and then group rows 100-200. Workbook wb = new SXSSFWorkbook(100); Sheet sh = wb.createSheet(); for (int rownum = 0; rownum < 1000; rownum++) { Row row = sh.createRow(rownum); if(rownum == 200) { sh.groupRow(100, 200); } } for (int rownum = 0; rownum < 1000; rownum++) { Row row = sh.createRow(rownum); } sh.groupRow(100, 200);
Please ignore my previous post, I occasionally submitted it too early. Support for grouping rows in SXSSF has been committed in r1295058 Please note that the rows being grouped must be in the memory window, you cannot write 1000000 rows and then group rows 100-200. Examples: Workbook wb = new SXSSFWorkbook(100); Sheet sh = wb.createSheet(); for (int rownum = 0; rownum < 1000; rownum++) { Row row = sh.createRow(rownum); if(rownum == 200) { // correct: group rows while they are in memory sh.groupRow(100, 200); } } for (int rownum = 0; rownum < 1000; rownum++) { Row row = sh.createRow(rownum); } // wrong: rows are already flushed and groupRow has no effect sh.groupRow(100, 200); Yegor
Yegor, How do you group rows that have been flushed, i.e. are not in the memory window now?