You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Aram Mirzadeh <aw...@mbcli.com> on 2013/12/11 20:17:19 UTC

Odd behavior in POI 3.10-beta1 & java7

I have this method for a number of years and I think when I upgaded to 
3.10-beta1 I started to see this odd behavior.   I'm also running 64-bit 
jdk build 1.7.0_25-b17, in eclipse Juno (64bit) on windows 7 (64bit).

The first 15 rows (all columns), the text of the cell is replaced with a 
numeric value, it's the same value each time but I can't figure out 
where it's coming from.

Commenting out the cell.setCellType(Cell.CELL_TYPE_NUMERIC); does indeed 
fix the problem.

Any ideas?

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.CellRangeAddress;
....
/**
      * Create the data sheet based on the sheet name and the sql provided
      *
      * @param sheetName
      * @param result
      * @throws SQLException
      */
/*
     colcount = 16
     result.length = 44
     row 1 = header
     sheetname.length=30
     all xssf
/*
     public void createDataSheet (Workbook wb, String sheetName, 
Result<?> result) throws SQLException {
         int colCount = 0;
         Sheet s = wb.createSheet(sheetName);
         logger.log(Level.DEBUG, String.format("Working on sheet %s for 
%s.",productName, sheetName));
         colCount = buildSheet(s, result);
         CellRangeAddress cra = new CellRangeAddress(0, 0, 0, colCount);
         logger.log(Level.TRACE, "Creating auto filter...");
         s.setAutoFilter(cra);
         for (int i = 0; i < colCount; i++) {
             s.autoSizeColumn(i);
             if (s.getColumnWidth(i) > 20) s.setColumnWidth(i, 20 * 256);
             Row row = getRow(wb.getSheet(sheetName), i);
             for (int j = 0; j < result.size(); j++) {
                 Cell cell = getCell(row, j);
/****
                 cell.setCellType(Cell.CELL_TYPE_NUMERIC);
*****/
             }
         }
         logger.log(Level.TRACE, "Finished createDataSheet.");
     }




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


Re: Odd behavior in POI 3.10-beta1 & java7

Posted by Nick Burch <ap...@gagravarr.org>.
On Thu, 12 Dec 2013, Aram Mirzadeh wrote:
> On 12/11/2013 11:12 PM, Nick Burch wrote:
>>> Commenting out the cell.setCellType(Cell.CELL_TYPE_NUMERIC); does indeed 
>>> fix the problem.
>> 
>> Why are you calling setCellType(Cell.CELL_TYPE_NUMERIC) on the cells? 
>> Generally this isn't needed - if reading you want the type the cell already 
>> has, if writing you normally let POI set the type when you set the value
>
> I'm writing, but POI is setting some of them to general when they are in fact 
> numeric.   But either way the resulting behavior isn't expected right?

Cell Type != Cell Formatting

Cell Type is a low level thing about how it gets written to the file. Cell 
Formatting is about how a number gets turned into soemthing on your screen

General is one of the well known formattings. If you want a different 
formatting applied, create a cell style, set the format on that (could be 
another well known one), and apply that cell style

Nick

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


Re: Odd behavior in POI 3.10-beta1 & java7

Posted by Aram Mirzadeh <aw...@mbcli.com>.
On 12/11/2013 11:12 PM, Nick Burch wrote:
> On Wed, 11 Dec 2013, Aram Mirzadeh wrote:
>> The first 15 rows (all columns), the text of the cell is replaced 
>> with a numeric value, it's the same value each time but I can't 
>> figure out where it's coming from.
>>
>> Commenting out the cell.setCellType(Cell.CELL_TYPE_NUMERIC); does 
>> indeed fix the problem.
>
> Why are you calling setCellType(Cell.CELL_TYPE_NUMERIC) on the cells? 
> Generally this isn't needed - if reading you want the type the cell 
> already has, if writing you normally let POI set the type when you set 
> the value
>
> Nick

I'm writing, but POI is setting some of them to general when they are in 
fact numeric.   But either way the resulting behavior isn't expected right?

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


Re: Odd behavior in POI 3.10-beta1 & java7

Posted by Nick Burch <ap...@gagravarr.org>.
On Wed, 11 Dec 2013, Aram Mirzadeh wrote:
> The first 15 rows (all columns), the text of the cell is replaced with a 
> numeric value, it's the same value each time but I can't figure out where 
> it's coming from.
>
> Commenting out the cell.setCellType(Cell.CELL_TYPE_NUMERIC); does indeed fix 
> the problem.

Why are you calling setCellType(Cell.CELL_TYPE_NUMERIC) on the cells? 
Generally this isn't needed - if reading you want the type the cell 
already has, if writing you normally let POI set the type when you set the 
value

Nick

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