-1

I need to read from formatted cells in Excel where numbers are stored as text in Java using Apache POI and extract the cells' contents as strings in their original format.

shA.t
  • 16,580
  • 5
  • 54
  • 111
Saber
  • 167
  • 1
  • 2
  • 6
  • 2
    What have tried so far? Please show us your code. – JanTheGun Apr 17 '15 at 11:41
  • 1
    We won't write your code for you, but we are here to help you! Post what you've tried along with any errors or problems that you've experienced, and then we'll point you towards the finish line. – JNYRanger Apr 21 '15 at 01:26
  • Did you try using [DataFormatter](http://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/DataFormatter.html)? – Gagravarr Apr 23 '15 at 17:02

1 Answers1

0

This works for me (with Apache POI 3.11):

    FileInputStream fileInputStream = new FileInputStream("test.xlsx");
    Workbook workBook = new XSSFWorkbook(fileInputStream);
    Sheet sheet = workBook.getSheetAt(0);

    CellReference cellReference = new CellReference("A1");
    Row row = sheet.getRow(cellReference.getRow());
    Cell cell = row.getCell(cellReference.getCol());

    System.out.println(cell.getStringCellValue());
Javide
  • 2,477
  • 5
  • 45
  • 61
  • As per [the Apache POI Docs](http://poi.apache.org/spreadsheet/quick-guide.html#FileInputStream), if you have a file, don't go via an input stream as it's slower and uses more memory! – Gagravarr Apr 23 '15 at 17:01