0

I am parsing data from an excel file and adding it to my data base using HSSFCell to parse the Excel file, I am using the following code to read the file

public void printCellDataToConsole(Vector dataHolder) throws SQLException {
            // this is for the rows in the file, set to one to skip the headings
            List<String> studentInformation = new ArrayList<>();
            for (int i = 1; i < dataHolder.size(); i++) {
                    Vector cellStoreVector = (Vector) dataHolder.elementAt(i);
                    // this is for the colums in the table
                    for (int j = 0; j < cellStoreVector.size(); j++) {
                            HSSFCell myCell = (HSSFCell) cellStoreVector.elementAt(j);
                            String stringCellValue = myCell.toString();
                            System.out.print(stringCellValue + "\t");                  
                    }
                    connectToDatabase.ammendTableInDatabase("INSERT INTO Student VALUES (" + cellStoreVector.get(0) + ",'" + cellStoreVector.get(1) + "','" + cellStoreVector.get(2) + "','" + cellStoreVector.get(3) + "','" + cellStoreVector.get(4) + "'," + cellStoreVector.get(5) + ",'" + cellStoreVector.get(6) + "')");
                    System.out.println();
            }
    }

Everything is working but when i try to read any value like the following

111223361
111223362
111223364
111223363
111223366

It reads them as the following

1.11223361E8
1.11223362E8
1.11223364E8
1.11223363E8
1.11223366E8

Why is this happening and how do i solve it?

4
  • Because I am also interesseted in reading values from Excel files, what framework do you use for doing that? Commented Sep 10, 2012 at 10:06
  • 1
    POI is my guess, since HSSFCell was mentioned. I'd recommend Andy Khan's JExcel over POI. Commented Sep 10, 2012 at 10:07
  • @reporter: well i am using poi-3.8-20120326.jar to parse the excel files, do you want to know anything else? Commented Sep 10, 2012 at 10:09
  • @ duffymo : Does JExcel support new data format? stackoverflow.com/questions/4763624/… mentions JExel cannot support new version. (May be the answer need a tweek) Commented Sep 10, 2012 at 10:10

3 Answers 3

3

1.11223361E8 means 1.11223361 x (10 ^ 8), so 111223361 = 1.11223361E8...

If you want to get it well formatted, use Double.valueOf("1.11223361E8").longValue().

Sign up to request clarification or add additional context in comments.

1 Comment

yes this solved the problem and thanks for explaining why the numbers where appearing in the format they where appearing in :)
1

Try using:

cellValueLong = Long.valueOf(myCell.toString());

I faced the same problem myself a few weeks ago. This happens because the number you are extrating as a string, comes in scientific notation format. And since you get it as a string and not as a long/int/(whatever) it returns the string value of that number in that format.

1 Comment

I tried this but myCell.Value gives the following: cannot find symbol symbol: variable Value location: variable myCell of type org.apache.poi.hssf.usermodel.HSSFCell
0

for getting values from excel sheet.this is the best solution.It may help u.

https://stackoverflow.com/a/12067137/1211000

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.