https://issues.apache.org/bugzilla/show_bug.cgi?id=53514

Yegor Kozlov <[email protected]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |INVALID

--- Comment #8 from Yegor Kozlov <[email protected]> ---
You are creating a cell style per row and this is wrong, see
http://poi.apache.org/faq.html#faq-N100EF

Move creation of cell style outside of the loop and define two styles for odd
and even rows. Below is my modification of your code that works properly:  

       try {


            int headerLength = 15;
            int noofrows = 48575;


            SXSSFWorkbook workbook = new SXSSFWorkbook(50);
            workbook.setCompressTempFiles(true);


            SXSSFSheet worksheet = null;


            String header = "";
            CellStyle cellStyle = workbook.createCellStyle();

            Font font = workbook.createFont();
            Font fontd = workbook.createFont();

            String data = "";

            SXSSFCell cell = null;
            CellStyle cellStyle1 = null;
            CellStyle cellStyle2 = null;

            SXSSFRow row = null;
            int sheetNo = 1;

            cellStyle.setFillForegroundColor(IndexedColors.ROYAL_BLUE.index);
            cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
            font.setBoldweight(Font.BOLDWEIGHT_BOLD);
            font.setColor(IndexedColors.WHITE.index);
            font.setFontHeightInPoints((short) 10);
            font.setFontName("Arial");
            cellStyle.setFont(font);

            fontd.setColor(IndexedColors.BLACK.index);
            fontd.setFontHeightInPoints((short) 10);
            fontd.setFontName("Arial");


            cellStyle1 = workbook.createCellStyle();
           
cellStyle1.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.index);
            cellStyle1.setFillPattern(CellStyle.SOLID_FOREGROUND);
            cellStyle1.setFont(fontd);

            cellStyle2 = workbook.createCellStyle();
            cellStyle2.setFont(fontd);

            System.out.println("Matrix Report noofrows::" + noofrows);
            for (long i = 0, rowNo = 1; i < noofrows; i++, rowNo++) {

                if (rowNo == 1048575) {
                    rowNo = 1;
                    sheetNo++;
                }
                if (rowNo == 1) {
                    worksheet = (SXSSFSheet) workbook.createSheet("Matrix
Report " + sheetNo);

                    row = (SXSSFRow) worksheet.createRow(0);

                    for (int hl = 0; hl < headerLength; hl++) {
                        cell = (SXSSFCell) row.createCell(hl);
                        header = hl + "";
                        cell.setCellValue(header);
                        cell.setCellStyle(cellStyle);

                        cell = null;
                    }
                }

                row = (SXSSFRow) worksheet.createRow((int) rowNo);



                for (int j = 0; j < headerLength; j++) {

                    cell = (SXSSFCell) row.createCell(j);
                    data = j + "";

                    if (data == null) data = "";

                    try {
                        cell.setCellValue(Long.parseLong(data));
                    } catch (NumberFormatException e) {
                        try {
                            cell.setCellValue(Double.parseDouble(data));
                        } catch (NumberFormatException ee) {
                            cell.setCellValue(data);
                        } catch (NullPointerException ee) {
                            cell.setCellValue(data);
                        }
                    } catch (NullPointerException e) {
                        cell.setCellValue(data);
                    }

                    cell.setCellStyle(rowNo%2 != 0 ? cellStyle1 : cellStyle2);

                }
            }

            FileOutputStream fileOut = new
FileOutputStream("MatrixReport.xlsx");
            workbook.write(fileOut);
            fileOut.close();

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

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to