You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Vijayakumar Gowdaman <vi...@db.com> on 2010/01/12 10:45:40 UTC
identifying the date cell
I am using the POI version 3.5. I want to identify a Cell is a date
formatted cell. I was looking at the interface
org.apache.poi.ss.usermodel.Cell
which is not having a field to identify a date formatted cell.
When I tried the below code
CellReference cellReference = new CellReference("A5");
Row row = sheet.getRow(cellReference.getRow());
Cell cell = row.getCell(cellReference.getCol());
int cellFormat = cell.getCellType();
the value of the cellFormat is 0 for both numeric and date fields.
But I can alternativley identify a date cell by using below code
if(cellFormat == CELL.CELL_TYPE_NUMERIC) {
if(DateUtil.isCellDateFormatted(cell)) {
//Date cell
} else {
//Numeric cell
}
}
but is there a way to check the date cell straight away with out calling
the DateUtil class.
Regards,
Vijayakumar Gowdaman
---
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
Please refer to http://www.db.com/en/content/eu_disclosures.htm for additional EU corporate and regulatory disclosures.
Re: identifying the date cell
Posted by MSB <ma...@tiscali.co.uk>.
If you want the date as a String formatted just the way the user sees it in
the workbook, then you can simply call the formatCellValue(Cell) method of
the org.apache.poi.ss.usermodel.DataFormatter class. It will recover the
value from the cell, apply the formatting and return a String to you that
can be used on reports, etc. In fact, if all you want to do is read through
the worksheet cell be cell and retrieve each cells value as a formatted
String, then there is really no need to text the cells type at all as the
method simply accepts a reference to a Cell.
Yours
Mark B
VK123 wrote:
>
> Thanks for the reply Mark.
>
> That's exactly I am doing in my code.
>
> Once it is a number then I am using a getDataFormatString() to get the
> format of the date.
>
>
> Regards,
>
> Vijayakumar Gowdaman
>
> Group Technology & Operations (GTO)
> Global Markets
> Deutsche Bank
> off: 02075456250
> Mob:07789773998
>
>
>
> MSB <ma...@tiscali.co.uk>
> 12/01/2010 16:20
> Please respond to
> "POI Users List" <us...@poi.apache.org>
>
>
> To
> user@poi.apache.org
> cc
>
> Subject
> Re: identifying the date cell
>
>
>
>
>
>
>
> No, there is no other way. The reason is that dates are actually stored as
> numbers - long integers I think - and then formatted so that the user of
> the
> worksheet sees a date in the format most familiar to them. That is why
> there
> is a need for the second check; knowing that the cell contains a number is
> not enough, it is necessary to look at the format applied to the cell to
> determine if it contains a date or not.
>
> Yours
>
> Mark B
>
>
> VK123 wrote:
>>
>> I am using the POI version 3.5. I want to identify a Cell is a date
>> formatted cell. I was looking at the interface
>> org.apache.poi.ss.usermodel.Cell
>> which is not having a field to identify a date formatted cell.
>>
>> When I tried the below code
>>
>> CellReference cellReference = new CellReference("A5");
>> Row row = sheet.getRow(cellReference.getRow());
>> Cell cell = row.getCell(cellReference.getCol());
>> int cellFormat = cell.getCellType();
>>
>> the value of the cellFormat is 0 for both numeric and date fields.
>>
>> But I can alternativley identify a date cell by using below code
>>
>> if(cellFormat == CELL.CELL_TYPE_NUMERIC) {
>> if(DateUtil.isCellDateFormatted(cell)) {
>> //Date cell
>> } else {
>> //Numeric cell
>> }
>> }
>>
>> but is there a way to check the date cell straight away with out calling
>
>> the DateUtil class.
>>
>>
>> Regards,
>>
>> Vijayakumar Gowdaman
>>
>>
>> ---
>>
>> This e-mail may contain confidential and/or privileged information. If
> you
>> are not the intended recipient (or have received this e-mail in error)
>> please notify the sender immediately and delete this e-mail. Any
>> unauthorized copying, disclosure or distribution of the material in this
>> e-mail is strictly forbidden.
>>
>> Please refer to http://www.db.com/en/content/eu_disclosures.htm for
>> additional EU corporate and regulatory disclosures.
>>
>
> --
> View this message in context:
> http://old.nabble.com/identifying-the-date-cell-tp27125003p27130100.html
> Sent from the POI - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>
>
>
>
> ---
>
> This e-mail may contain confidential and/or privileged information. If you
> are not the intended recipient (or have received this e-mail in error)
> please notify the sender immediately and delete this e-mail. Any
> unauthorized copying, disclosure or distribution of the material in this
> e-mail is strictly forbidden.
>
> Please refer to http://www.db.com/en/content/eu_disclosures.htm for
> additional EU corporate and regulatory disclosures.
>
--
View this message in context: http://old.nabble.com/identifying-the-date-cell-tp27125003p27130535.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: identifying the date cell
Posted by Vijayakumar Gowdaman <vi...@db.com>.
Thanks for the reply Mark.
That's exactly I am doing in my code.
Once it is a number then I am using a getDataFormatString() to get the
format of the date.
Regards,
Vijayakumar Gowdaman
Group Technology & Operations (GTO)
Global Markets
Deutsche Bank
off: 02075456250
Mob:07789773998
MSB <ma...@tiscali.co.uk>
12/01/2010 16:20
Please respond to
"POI Users List" <us...@poi.apache.org>
To
user@poi.apache.org
cc
Subject
Re: identifying the date cell
No, there is no other way. The reason is that dates are actually stored as
numbers - long integers I think - and then formatted so that the user of
the
worksheet sees a date in the format most familiar to them. That is why
there
is a need for the second check; knowing that the cell contains a number is
not enough, it is necessary to look at the format applied to the cell to
determine if it contains a date or not.
Yours
Mark B
VK123 wrote:
>
> I am using the POI version 3.5. I want to identify a Cell is a date
> formatted cell. I was looking at the interface
> org.apache.poi.ss.usermodel.Cell
> which is not having a field to identify a date formatted cell.
>
> When I tried the below code
>
> CellReference cellReference = new CellReference("A5");
> Row row = sheet.getRow(cellReference.getRow());
> Cell cell = row.getCell(cellReference.getCol());
> int cellFormat = cell.getCellType();
>
> the value of the cellFormat is 0 for both numeric and date fields.
>
> But I can alternativley identify a date cell by using below code
>
> if(cellFormat == CELL.CELL_TYPE_NUMERIC) {
> if(DateUtil.isCellDateFormatted(cell)) {
> //Date cell
> } else {
> //Numeric cell
> }
> }
>
> but is there a way to check the date cell straight away with out calling
> the DateUtil class.
>
>
> Regards,
>
> Vijayakumar Gowdaman
>
>
> ---
>
> This e-mail may contain confidential and/or privileged information. If
you
> are not the intended recipient (or have received this e-mail in error)
> please notify the sender immediately and delete this e-mail. Any
> unauthorized copying, disclosure or distribution of the material in this
> e-mail is strictly forbidden.
>
> Please refer to http://www.db.com/en/content/eu_disclosures.htm for
> additional EU corporate and regulatory disclosures.
>
--
View this message in context:
http://old.nabble.com/identifying-the-date-cell-tp27125003p27130100.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
---
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
Please refer to http://www.db.com/en/content/eu_disclosures.htm for additional EU corporate and regulatory disclosures.
Re: identifying the date cell
Posted by MSB <ma...@tiscali.co.uk>.
No, there is no other way. The reason is that dates are actually stored as
numbers - long integers I think - and then formatted so that the user of the
worksheet sees a date in the format most familiar to them. That is why there
is a need for the second check; knowing that the cell contains a number is
not enough, it is necessary to look at the format applied to the cell to
determine if it contains a date or not.
Yours
Mark B
VK123 wrote:
>
> I am using the POI version 3.5. I want to identify a Cell is a date
> formatted cell. I was looking at the interface
> org.apache.poi.ss.usermodel.Cell
> which is not having a field to identify a date formatted cell.
>
> When I tried the below code
>
> CellReference cellReference = new CellReference("A5");
> Row row = sheet.getRow(cellReference.getRow());
> Cell cell = row.getCell(cellReference.getCol());
> int cellFormat = cell.getCellType();
>
> the value of the cellFormat is 0 for both numeric and date fields.
>
> But I can alternativley identify a date cell by using below code
>
> if(cellFormat == CELL.CELL_TYPE_NUMERIC) {
> if(DateUtil.isCellDateFormatted(cell)) {
> //Date cell
> } else {
> //Numeric cell
> }
> }
>
> but is there a way to check the date cell straight away with out calling
> the DateUtil class.
>
>
> Regards,
>
> Vijayakumar Gowdaman
>
>
> ---
>
> This e-mail may contain confidential and/or privileged information. If you
> are not the intended recipient (or have received this e-mail in error)
> please notify the sender immediately and delete this e-mail. Any
> unauthorized copying, disclosure or distribution of the material in this
> e-mail is strictly forbidden.
>
> Please refer to http://www.db.com/en/content/eu_disclosures.htm for
> additional EU corporate and regulatory disclosures.
>
--
View this message in context: http://old.nabble.com/identifying-the-date-cell-tp27125003p27130100.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org