XSSFSheet get all cell type values as string

20,246

Someone else already supplied a generic implementation that does what you are looking to do. POI doesn't have anything directly but it's easy enough to make a helper method/class.

Share:
20,246
sunleo
Author by

sunleo

Enthusiastic java tech Lover!!!! திரை கடலோடியும் திரவியம் தேடு http://www.animatedrecursion.com/intro/introduction.html Reversing a nested loop http://dwite.ca/ How to config Tomcat to serve images from an external folder outside webapps? How is my id being generated with JPA using Hibernate with the Oracle 10g dialect? http://balusc.blogspot.be/2007/04/imageservlet.html

Updated on January 29, 2021

Comments

  • sunleo
    sunleo over 3 years

    Is there any possiblity to get all types(numeric,date,string etc) as String only.I couldn't find such methods.

    sheet.getCell(rowIndex,colIndex) like this ?

    InputStream ExcelFileToRead = new FileInputStream(file1);
    XSSFWorkbook  wb = new XSSFWorkbook(ExcelFileToRead);
    XSSFWorkbook test = new XSSFWorkbook(); 
    XSSFSheet sheet = wb.getSheetAt(0);
    XSSFRow row;
    XSSFCell cell;
    
    Iterator rows = sheet.rowIterator();
    String[] Excelarray=new String[26];
    int count=0;
    Map<String, String> data = new HashMap<String, String>();
    
    while (rows.hasNext())
    {
    row=(XSSFRow) rows.next();
    Iterator cells = row.cellIterator();
    while (cells.hasNext())
    {
    cell=(XSSFCell) cells.next();
    if (cell.getCellType() == XSSFCell.CELL_TYPE_STRING)
    {
    System.out.print(cell.getStringCellValue()+",");
    }
    else if(cell.getCellType() == XSSFCell.CELL_TYPE_NUMERIC)
    {
    System.out.print(cell.getNumericCellValue()+",");
    }
    else
    {
    }
    }
    System.out.println("----Closed");
    }