I have a code to read a xls file in java.
But the problem is that when I am read the numeric value that time it gives me wrong format value.
My code is
String fname = "D:/Vijay/BRS_docs/10168/19.11.2014/19.11.2014/Bank/Debit Open Item File/INF 21 Case.xls";
FileInputStream fis = new FileInputStream(fname);
HSSFWorkbook wb = new HSSFWorkbook(fis);
HSSFSheet sheet = (HSSFSheet) wb.getSheetAt(0);
FormulaEvaluator formulaEval = wb.getCreationHelper().createFormulaEvaluator();
fis = new FileInputStream(fname);
Iterator rowIter = sheet.rowIterator();
while (rowIter.hasNext()) {
HSSFRow myRow = (HSSFRow) rowIter.next();
Iterator cellIter = myRow.cellIterator();
while (cellIter.hasNext()) {
String cellvalue = "";
HSSFCell myCell = (HSSFCell) cellIter.next();
cellvalue = ""+ formulaEval.evaluate(myCell).formatAsString();
System.out.println("cellvalue--" + cellvalue);
}
}
I have value 119710179 this is numeric but when I am syso that time it display cellvalue--1.19710179E8
I used this code also but same numeric fomat
Iterator cellIter = myRow.cellIterator();
while (cellIter.hasNext()) {
String cellvalue = "";
HSSFCell myCell = (HSSFCell) cellIter.next();
if (myCell.getCellType() == HSSFCell.CELL_TYPE_STRING) {
System.out.println("11");
cellvalue = myCell.getStringCellValue();
} else if (myCell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {
System.out.println("22");
if (DateUtil.isCellDateFormatted(myCell)) {
cellvalue = myCell.getDateCellValue().toString();
} else {
cellvalue = Double.toString(myCell.getNumericCellValue());
}
} else if (myCell.getCellType() == HSSFCell.CELL_TYPE_BOOLEAN) {
System.out.println("33");
cellvalue = "" + myCell.getBooleanCellValue();
} else if (myCell.getCellType() == HSSFCell.CELL_TYPE_FORMULA) {
System.out.println("44");
cellvalue = ""+ formulaEval.evaluate(myCell).formatAsString();
} else if (myCell.getCellType() == HSSFCell.CELL_TYPE_BLANK) {
System.out.println("55");
cellvalue = "";
}
System.out.println("cellvalue--" + cellvalue);
}
}
All values are display properly but this only one value get wrong. Thanks in advance