Welcome to the Question and Answer site for Software Testing Professionals

You can get your queries resolved from Software Testing Professionals.

Ask a Question

Get answers and give answers to questions from other members.

View All Questions

Get votes and earn points to build your reputation in community.

View Hot Questions

0
Reading Numeric data form excel in data driven Framework ?

Solved 1 Answers 25 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 (733 points)
selected by
2Comments
commented by (143 points)
Thank you and
i will try it ..
commented by (143 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.

We have resolved 1.2k+ Software Testing queries!

Software Testing Board Weekly update

We will send you handpicked questions that you would love to answer.

View previous campaigns.

Top Contributors

...