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; }
Firstly, please do not use bugzilla for use questions, use the mailing list for that. Bugzilla is only for bugs Secondly, look at the various HSSF formatter classes, as by default poi returns the raw values stored in the file