You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Sergey Maslov <th...@gmail.com> on 2012/01/11 09:43:09 UTC

poi 3.8 SXSSF- Applying of rows grouping causes the workbook file became invalid.

I get the unreadable content error in the MS Excel after applying rows
grouping in the SXSSF Workbook.
Brief overview of the document content (office open xml structure)
shows that Apache POI puts tags in the sheet1.xml incorrectly.
For outlined leveled rows the elements <row> are written twice: at the
top of the <sheetData> and further in the flow.

For example (the code to reproduce is written below), the rows 3, 4
and 5 are described :
<sheetData><row r="3" outlineLevel="1"/><row r="4"
outlineLevel="1"/><row r="5" outlineLevel="1"/>
and later
<row r="3">
<c r="A3" ....

It is reproduced in the poi 3.8 beta 4 and 3.8 beta 5 and is not
repoduced using XSSF xlsx generation.
Could I miss something necessary in the code or I should submit the bug?

____
import java.io.FileOutputStream;

import org.apache.poi.ss.usermodel.Cell;

import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellReference;

import org.apache.poi.xssf.streaming.SXSSFWorkbook;

public class PoiGroup {

    public static void main(String[] args) throws Exception {
        try {

            Workbook wb = new SXSSFWorkbook(10);
            Sheet sh = wb.createSheet();
            for(int rownum = 0; rownum < 10; rownum++){
                Row row = sh.createRow(rownum);
                for(int cellnum = 0; cellnum < 10; cellnum++){
                    Cell cell = row.createCell(cellnum);
                    String address = new CellReference(cell).formatAsString();
                    cell.setCellValue(address);
                }

            }

            sh.groupRow(2, 4);
            sh.setRowSumsBelow(false);

            FileOutputStream out = new FileOutputStream("d:\\sxssf.xlsx");
            wb.write(out);
            out.close();

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}
____

The code doing the same with XSSFWorkbook still works fine.

____
import java.io.FileOutputStream;

import org.apache.poi.ss.usermodel.Cell;

import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.util.CellReference;

import org.apache.poi.xssf.usermodel.XSSFWorkbook;


public class PoiOld {
    public static void main(String[] args) throws Exception {
    try {

        XSSFWorkbook workbook = new XSSFWorkbook();
        FileOutputStream fileOut = new FileOutputStream("d:/Book2.xlsx");
        Sheet sh = workbook.createSheet();
        for(int rownum = 0; rownum < 10; rownum++){
            Row row = sh.createRow(rownum);
            for(int cellnum = 0; cellnum < 10; cellnum++){
                Cell cell = row.createCell(cellnum);
                String address = new CellReference(cell).formatAsString();
                cell.setCellValue(address);
            }

        }
        sh.groupRow(2, 4);
        sh.setRowSumsBelow(false);

        workbook.write(fileOut);
        fileOut.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
____

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org