Results 1 to 2 of 2
  1. #1
    sauloneves is offline Member
    Join Date
    Apr 2016
    Posts
    1
    Rep Power
    0

    Default How to read cell blank with apache poi using XSSFReader

    Hi,

    how to read cell blank with apache poi using XSSFReader ?

    I need to use XSSFReader to read large excel files....


    Regards,
    Saulo Neves

  2. #2
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,983
    Rep Power
    8

    Default Re: How to read cell blank with apache poi using XSSFReader

    I am not sure how it's done with XSSFReader. I do know how I do it with an XSSFWorkbook. This is my getValue(row,column) method. Maybe you can use it.

    Java Code:
            int cellType = cell.getCellType();
            Object result = null;
    
            if (cellType == Cell.CELL_TYPE_BLANK) {
                result = null;
            }
            else if (cellType == Cell.CELL_TYPE_NUMERIC) {
                result = cell.getNumericCellValue();
            }
            else if (cellType == Cell.CELL_TYPE_FORMULA) {
                int type = -1;
    
                if (evaluateFormulas) {
                    try {
                        type = formulaEvaluator.evaluateFormulaCell(cell);
                    }
                    catch (Exception e) {
                        type = cell.getCachedFormulaResultType();
                    }
                }
                else {
                    type = cell.getCachedFormulaResultType();
                }
    
                switch (type) {
                    case Cell.CELL_TYPE_NUMERIC:
                        return cell.getNumericCellValue();
                    case Cell.CELL_TYPE_STRING:
                        return cell.getStringCellValue();
                    case Cell.CELL_TYPE_BOOLEAN:
                        return cell.getBooleanCellValue();
                    case Cell.CELL_TYPE_ERROR:
                        try {
                            return FormulaError.forInt(cell.getErrorCellValue()).getString();
                        }
                        catch (Exception e1) {
                            return "#UNKNOWN";
                        }
                }
    
            }
            else if (cellType == Cell.CELL_TYPE_BOOLEAN) {
                result = cell.getBooleanCellValue();
            }
            else if (cellType == Cell.CELL_TYPE_ERROR) {
                result = cell.getErrorCellValue();
            }
            else if (cellType == Cell.CELL_TYPE_STRING) {
                result = cell.getRichStringCellValue().getString();
            }
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

Similar Threads

  1. Replies: 1
    Last Post: 12-11-2015, 02:10 PM
  2. Replies: 5
    Last Post: 03-27-2014, 01:14 PM
  3. Read/write to same excel file using Apache POI
    By anji2010 in forum Apache POI
    Replies: 4
    Last Post: 01-17-2014, 10:57 AM
  4. read excel cell value using cell id or name
    By Ambika in forum Apache POI
    Replies: 0
    Last Post: 02-22-2013, 12:01 PM
  5. Read Bookmarks from a word document using apache POI
    By anuskesh in forum Advanced Java
    Replies: 0
    Last Post: 07-28-2010, 04:36 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •