Join 500+ Software Testing professionals. Solve problem and get your problem solved. Register Now!

0
Reading Numeric data form excel in data driven Framework ?

Solved 1 Answers 32 Views
0 1
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
Best answer
0
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.
answered by (822 points)
selected by
2Comments
commented by (188 points)
Thank you and
i will try it ..
commented by (188 points)
@mayur  
Thank you
am getting exact values from excel

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.
...