while retrieving the value it is giving in the exponential format for big numbers.
while (cells.hasNext ())
{
HSSFCell cell = cells.next ();
System.out.println ("Cell No.: " + cell.getCellNum ());
/*
* Now we will get the cell type and display the values
* accordingly.
*/
switch (cell.getCellType ())
{
case HSSFCell.CELL_TYPE_NUMERIC :
{
// cell type numeric.
System.out.println ("Numeric value: " + cell.getNumericCellValue());
break;
}
it is giving values for the numbers whose digit are greater than 7eg.(12345678) as in exponential.Can u help me to get the value in the same format.
Now, let's find the index of the last row on a given Sheet. Apache POI provides two methods that help count rows: getLastRowNum() and getPhysicalNumberOfRows().
To Read and Write Excel file in Java, Apache provides a very famous library POI. This library is capable enough to read and write both XLS and XLSX file format of Excel. To read XLS files, an HSSF implementation is provided by POI library. To read XLSX, XSSF implementation of POI library will be the choice.
Easiest way is to use a BigDecimal:
System.out.println("Numeric value: " + new BigDecimal(cell.getNumericCellValue()));
I'd use an instance of DecimalFormat
.
DecimalFormat df = new DecimalFormat("#.00000000");
System.out.print(df.format(cell.getNumericCellValue()));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With