Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print a number greater than 7 digits using poi(2.5) from excel sheet in the console using java

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.

like image 221
sumit Avatar asked Jan 20 '11 14:01

sumit


People also ask

How do I get the number of rows in Excel using Apache POI?

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().

How read and write data from Excel in Java?

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.


2 Answers

Easiest way is to use a BigDecimal:

System.out.println("Numeric value: " + new BigDecimal(cell.getNumericCellValue()));
like image 186
dogbane Avatar answered Oct 20 '22 19:10

dogbane


I'd use an instance of DecimalFormat.

DecimalFormat df = new DecimalFormat("#.00000000");
System.out.print(df.format(cell.getNumericCellValue()));
like image 40
trashgod Avatar answered Oct 20 '22 18:10

trashgod