Kaan Kılıç
Kaan Kılıç

Reputation: 27

jExcel getting cell content missing

I read excel file correctly.For example my cell content is 0,987654321 in excel file.When I read it with jExcel api i reads just few chars of cell.For example 0,987.

here is my read excel code part:

 Cell A = sheet.getCell(1, 1);
 String stringA = A.getContents().toString();

How can I fix that problem.I want all content of cell.

Upvotes: 1

Views: 3334

Answers (2)

Shai Alon
Shai Alon

Reputation: 990

And in short:

if (A.getType() == CellType.NUMBER) {
    double doubleA = ((NumberCell) sheet.getCell(1, 1)).getValue();
}

Upvotes: 0

fvu
fvu

Reputation: 32953

getContents() is a basic routine to get the cell's content as a string. By casting the cell to the appropriate type (after testing that it's the expected type) you get access to the raw numeric value contained, like this

if (A.getType() == CellType.NUMBER) {
    NumberCell nc = (NumberCell) A;
    double doubleA = nc.getValue();
    // this is a double containing the exact numeric value that was stored 
    // in the spreadsheet
}

The key message here is: you can access any type of cell by casting to the appropriate subtype of Cell.
All this and a lot more is explained in the jexcelapi tutorial

Upvotes: 2

Related Questions