Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
474 views
by The go-to Tester (190 points)
edited by
Hi friends,

             an excel sheet consist of 3 column

         NAME      ID      RS    

         Abhishek  10    5000

         karthik     10    350.56

My questions is, By using Poi jar file i get value's form each cell by using switch case like

switch(c.getCellType()){

case Cell.CELL_TYPE_STRING:

return c.getStringCellValue();

case Cell.CELL_TYPE_NUMERIC:

return String.valueOf(c.getNumericCellValue());

default:

            return "Cell not found";

}

if only one column means i will type cast it but -> just consider "n" number columns having decimal value and "n" number columns having Integer value's .

like this am getting my value from excel like

my output :

Abhishek 10.0 5000.0 --> karthik  10.0 350.56

am getting Integer value as decimal value ?

there 's any solution for this i need to get  integer values as integer value and decimal values as decimal values

1 Answer

0 like 0 dislike
by Master (1.2k points)
selected by
 
Best answer
Have you tried using DataFormatter class?

DataFormatter will try its best to return the value as it looks like on the Excel file.

You can try the sample as below.

Workbook _workbook = WorkbookFactory.create(new File("my_file.xlsx"));
DataFormatter formatter = new DataFormatter();
Sheet s = _workbook.getSheetAt(0);
for (Row r : s) {
  for (Cell c : r) {
     System.out.println(formatter.formatCellValue(c));
  }
}

Try that and let us know.
by The go-to Tester (190 points)
Thank you and
i will try it ..
by The go-to Tester (190 points)
@mayur  
Thank you
am getting exact values from excel


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

1.4k questions

1.6k answers

866 comments

1.9k users

...