Bug 57426 - CellStyle not applying after some columns
Summary: CellStyle not applying after some columns
Status: RESOLVED WORKSFORME
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.10-FINAL
Hardware: PC All
: P2 major (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-01-08 11:06 UTC by Srinu
Modified: 2015-06-20 21:31 UTC (History)
0 users



Attachments
sample (27.00 KB, application/vnd.ms-excel)
2015-01-08 11:10 UTC, Srinu
Details
The result that I edit sample excel book to look cell value type. (10.00 KB, application/vnd.ms-excel)
2015-02-11 12:21 UTC, Akira Shiratsuki
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Srinu 2015-01-08 11:06:18 UTC
I have to write data more than 70 columns and 40K rows. 
After some no of columns CellStyle is not applying for entire column.
What i am doing is i am preparing one CellStyle per one column, while writing to data i am applying cellstyle to each cell.
My code is as follows.
    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFWorkbook workbook = new HSSFWorkbook();
    Sheet sheet = null;
    Row row = null;
    Cell cell = null;
    CellStyle[] cellStyle = new CellStyle[noofcolumnscount];

            cellStyle[colcount] = workbook.createCellStyle();
            cellStyle[colcount].setFont(dataFont);
            if (rptDetailsBean.getColumnDataType() != null && ("NUMBER".equalsIgnoreCase(rptDetailsBean.getColumnDataType()) || "CURRENCY".equalsIgnoreCase(rptDetailsBean.getColumnDataType()))) {
              cellStyle[colcount].setAlignment(HSSFCellStyle.ALIGN_RIGHT);
            } else {
              cellStyle[colcount].setAlignment(HSSFCellStyle.ALIGN_LEFT);
            }
            if (rptDetailsBean != null && rptDetailsBean.getFormat() != null) {
              if (!isFormatValid(rptDetailsBean.getFormat(), rptDetailsBean.getColumnDataType())) {
                throw new java.lang.Exception("Format at " + (colcount) + "is not valid");
              }
              cellStyle[colcount].setDataFormat(createHelper.createDataFormat().getFormat(rptDetailsBean.getFormat()));
            }
i am applying style while writing each cell while looping trough resultset

cell = row.createCell(colcount);
              int dataLength = 15;
              if ("DATE".equalsIgnoreCase(rptDetailsBean.getColumnDataType())) {
                if (rs.getTimestamp(selectClause) != null) {
                  cell.setCellValue(rs.getTimestamp(selectClause));
                  cell.setCellStyle(cellStyle[colcount]);
                } else {
                  cell.setCellValue("");
                  cell.setCellStyle(cellStyle[colcount]);
                }
              } else {
                if ("NUMBER".equalsIgnoreCase(rptDetailsBean.getColumnDataType()) || "CURRENCY".equalsIgnoreCase(rptDetailsBean.getColumnDataType())) {
                  if ((Double) rs.getDouble(selectClause) != null && !rs.wasNull())       {
                    cell.setCellValue(rs.getDouble(selectClause));
                    cell.setCellStyle(cellStyle[colcount]);
                  } else {
                    cell.setCellValue("");
                    cell.setCellStyle(cellStyle[colcount]);
                  }
                } else {
                  if (rs.getString(selectClause) != null) {
                    dataLength = rs.getString(selectClause).length();
                    cell.setCellValue(rs.getString(selectClause));
                    cell.setCellStyle(cellStyle[colcount]);
                  } else {
                    cell.setCellValue("");
                    cell.setCellStyle(cellStyle[colcount]);
                  }
                }
              }

Can you help in this.
Comment 1 Srinu 2015-01-08 11:10:05 UTC
Created attachment 32357 [details]
sample
Comment 2 Akira Shiratsuki 2015-02-11 12:21:02 UTC
Created attachment 32454 [details]
The result that I edit sample excel book to look cell value type.

What column is invalid? I see that the alignment of NUMBER type is right.
Comment 3 Dominik Stadler 2015-03-01 18:32:04 UTC
I tried to reproduce this with a simple test, but couldn't. Any chance you can create a self-contained unit-test which does not rely on any other code or variables? 

Also we have version 3.11 and 3.12-beta1 available with a number of fixes, can you verify that it still happens with those versions?

This will make it much easier to reproduce and look for a possible fix.
Comment 4 Dominik Stadler 2015-06-20 21:31:11 UTC
No response for some time, therefore resolving this for now, please reopen with the additional information described in the previous comment if this is still a problem for you with the latest version of POI.