You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Sascha Rühlow <sr...@gmail.com> on 2013/03/07 14:54:07 UTC

XSSFCell Problem with Cell.CELL_TYPE_STRING

Hi,
I am currently using apache poi 3.8 and have a little problem with String
values set to a XSSFCell using setCellValue().
If the String starts with - or another character used in Excel formulas,
the text is not formatted as text in Excel (like, when I am entering a '
before a numeric value to format them as text). So if I am trying to edit
the text field in Excel, it is interpreted as a formula whats is not really
what I want.

Is it possible to build something like the manually entered ' when setting
the cellValue?

Here's the code I am using:

 cell = row.createCell(ID);
 cell.setCellType(Cell.CELL_TYPE_STRING);
 cell.setCellValue("-Test");

Can anybody help me?

Best regards

RE: XSSFCell Problem with Cell.CELL_TYPE_STRING

Posted by "Hampson, Ken" <ke...@weareflood.com>.
What would happen if you set the Cellstyle to be 'Text' beforehand?

I'm not familiar with XSSF, but HSSF has this:

This is RPG but you'll get the gist:

Text = HssfWorkbook_createCellstyle( Book );    
DataFmt = HssfWorkbook_createDataFormat( Book );
String = new_String( '@' );                          
NumFmt = HssfDataFormat_getFormat( DataFmt: String );
HssfcellStyle_setDataFormat( Text: NumFmt );         


In this case I have a cellstyle variable called 'Text'. Dataformat = '@' (or the numeric index equivalent ) forces the cell that uses it to be character.

Hope that helps.

Cheers,
Ken



-----Original Message-----
From: Sascha Rühlow [mailto:sruehlow@gmail.com] 
Sent: Thursday, March 07, 2013 8:54 AM
To: user@poi.apache.org
Subject: XSSFCell Problem with Cell.CELL_TYPE_STRING

Hi,
I am currently using apache poi 3.8 and have a little problem with String values set to a XSSFCell using setCellValue().
If the String starts with - or another character used in Excel formulas, the text is not formatted as text in Excel (like, when I am entering a '
before a numeric value to format them as text). So if I am trying to edit the text field in Excel, it is interpreted as a formula whats is not really what I want.

Is it possible to build something like the manually entered ' when setting the cellValue?

Here's the code I am using:

 cell = row.createCell(ID);
 cell.setCellType(Cell.CELL_TYPE_STRING);
 cell.setCellValue("-Test");

Can anybody help me?

Best regards

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