1

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.

fvu
  • 32,488
  • 6
  • 61
  • 79
Kaan Kılıç
  • 27
  • 1
  • 6

2 Answers2

2

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

fvu
  • 32,488
  • 6
  • 61
  • 79
0

And in short:

if (A.getType() == CellType.NUMBER) {
    double doubleA = ((NumberCell) sheet.getCell(1, 1)).getValue();
}
Shai Alon
  • 969
  • 13
  • 21