https://issues.apache.org/bugzilla/show_bug.cgi?id=46673
Summary: How to get formatted value from cell?
Product: POI
Version: 3.5-dev
Platform: PC
OS/Version: Windows XP
Status: NEW
Severity: normal
Priority: P2
Component: XSSF
AssignedTo: [email protected]
ReportedBy: [email protected]
Thanks for giving this product to us.
In my project, i want to convert the xls(or xlsx file) into CSV file.
I dont know how to get the formated value from the cell
1. If the numeric cell have "$12,000" (With format) but i get only the value
(12000).
2. If the Date cell "12-May" but i get only number (23455).
I missed some thing in code.so plz anybody help me. how to get the formatted
value from the cell.
Here my code:
WorkbookFactory wbFact = new WorkbookFactory();
Workbook wbs = wbFact.create(new FileInputStream(file));
int noOfSheets = wbs.getNumberOfSheets();
FormulaEvaluator evaluator =
wbs.getCreationHelper().createFormulaEvaluator();
String csvString = "";
Sheet sheet = wbs.getSheetAt(sheetNo);
boolean isFirstRow = true;
for (Iterator rit = sheet.rowIterator(); rit.hasNext(); )
{
if(!isFirstRow)
{
csvString += "\r\n";
}
Row row = (Row)rit.next();
boolean isFirstCell = true;
for (Iterator cit = row.cellIterator(); cit.hasNext(); )
{
if(!isFirstCell)
{
csvString += ",";
}
Cell cell = (Cell)cit.next();
String val = "";
switch (cell.getCellType())
{
case Cell.CELL_TYPE_BOOLEAN:
val = String.valueOf(cell.getBooleanCellValue());
break;
case Cell.CELL_TYPE_NUMERIC:
val = String.valueOf(cell.getNumericCellValue());
break;
case Cell.CELL_TYPE_STRING:
val = String.valueOf(cell.getStringCellValue());
break;
case Cell.CELL_TYPE_BLANK:
break;
case Cell.CELL_TYPE_ERROR:
break;
case Cell.CELL_TYPE_FORMULA:
val = evaluator.evaluate(cell).formatAsString();
break;
}
csvString += "\"" + val + "\"";
isFirstCell = false;
}
isFirstRow = false;
}
return csvString;
}
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- 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]