Example usage for org.apache.poi.ss.usermodel Cell getBooleanCellValue

List of usage examples for org.apache.poi.ss.usermodel Cell getBooleanCellValue

Introduction

In this page you can find the example usage for org.apache.poi.ss.usermodel Cell getBooleanCellValue.

Prototype

boolean getBooleanCellValue();

Source Link

Document

Get the value of the cell as a boolean.

Usage

From source file:com.adobe.ags.curly.controller.DataImporterController.java

License:Apache License

private String getStringValueFromCell(Cell cell) {
    if (cell == null) {
        return null;
    }/*from ww  w .ja  va  2s .  co m*/
    int cellType = cell.getCellType();
    if (cellType == Cell.CELL_TYPE_FORMULA) {
        cellType = cell.getCachedFormulaResultType();
    }
    switch (cellType) {
    case Cell.CELL_TYPE_BOOLEAN:
        return Boolean.toString(cell.getBooleanCellValue());
    case Cell.CELL_TYPE_BLANK:
        return null;
    case Cell.CELL_TYPE_NUMERIC:
        double num = cell.getNumericCellValue();
        if (num == Math.floor(num)) {
            return Integer.toString((int) num);
        } else {
            return Double.toString(cell.getNumericCellValue());
        }
    case Cell.CELL_TYPE_STRING:
        return cell.getStringCellValue();
    default:
        return "???";
    }
}

From source file:com.alibaba.ims.platform.util.ExcelUtil.java

License:Open Source License

private static String getCellValue(Cell cell) {
    switch (cell.getCellType()) {
    case Cell.CELL_TYPE_STRING:
        return cell.getRichStringCellValue().getString();
    case Cell.CELL_TYPE_NUMERIC:
        if (org.apache.poi.ss.usermodel.DateUtil.isCellDateFormatted(cell)) {
            return DateUtil.format(cell.getDateCellValue(), "yyyy-MM-dd");
        } else {/*from ww w  .  ja v  a  2s.  co m*/
            return new DecimalFormat("0").format(cell.getNumericCellValue());
        }
    case Cell.CELL_TYPE_BOOLEAN:
        return String.valueOf(cell.getBooleanCellValue());
    case Cell.CELL_TYPE_FORMULA:
        return cell.getCellFormula();
    default:
        return null;
    }
}

From source file:com.amitycoin.enterprisetool.diagramInputServlet.java

@Override
@SuppressWarnings({ "null", "ValueOfIncrementOrDecrementUsed", "UnusedAssignment" })
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String filePath;//from ww  w.java2 s .co  m
    String docids;
    String userid;
    String a[][];
    a = new String[200][200];
    // database connection settings
    String dbURL = "jdbc:mysql://localhost:3306/enterprisedb";
    String dbUser = "root";
    String dbPass = "sandy";

    @SuppressWarnings("UnusedAssignment")
    Connection conn = null; // connection to the database
    userid = (String) request.getAttribute("uidM");
    String fname = (String) request.getAttribute("fnameM");
    int docid = (Integer) request.getAttribute("docidM");

    docids = "" + docid;
    String pathToWeb;
    pathToWeb = getServletContext().getRealPath(File.separator);
    System.out.println("pathtoweb:\t" + pathToWeb);
    filePath = pathToWeb + "readFiles\\";
    filePath = filePath + docids + userid + fname; //+.xls
    File myFile = new File(filePath);

    //boolean newExcel;
    //boolean oldExcel;
    String ext = FilenameUtils.getExtension(filePath);
    System.out.println("Extension: " + ext);

    FileInputStream fis = new FileInputStream(myFile);
    Workbook wb = null;
    if ("xls".equals(ext)) {
        // Finds the workbook instance for the file
        wb = new HSSFWorkbook(fis);

    } else if ("xlsx".equals(ext)) {
        wb = new XSSFWorkbook(fis);

    }

    @SuppressWarnings("null")
    Sheet mySheet;
    mySheet = wb.getSheetAt(0);

    // Get iterator to all the rows in current sheet
    Iterator<Row> rowIterator = mySheet.iterator();

    @SuppressWarnings("UnusedAssignment")
    int rowct = 0, colct = 0, colit = 0, ci = 0, ri = 0;

    // Traversing over each row of XLSX file
    while (rowIterator.hasNext()) {
        ri++;
        System.out.println("\nRi:\t" + ri);
        //Iterate over Rows
        Row row = rowIterator.next();

        if (1 == rowct) {
            colct = colit;
        }
        // For each row, iterate through each columns
        Iterator<Cell> cellIterator = row.cellIterator();
        ci = 0;
        while (cellIterator.hasNext()) {

            ci++;

            System.out.println("\nCi:\t" + ci);
            //Iterate over Columns
            Cell cell = cellIterator.next();

            switch (cell.getCellType()) {
            case Cell.CELL_TYPE_STRING:
                System.out.print(cell.getStringCellValue() + "\t");
                a[ri][ci] = cell.getStringCellValue();
                break;
            case Cell.CELL_TYPE_NUMERIC:
                System.out.print(cell.getNumericCellValue() + "\t");
                double temp = cell.getNumericCellValue();
                String dblValue = "" + temp;
                a[ri][ci] = dblValue;
                break;
            case Cell.CELL_TYPE_BOOLEAN:
                System.out.print(cell.getBooleanCellValue() + "\t");
                String tmp = "" + cell.getBooleanCellValue();
                a[ri][ci] = tmp;
                break;
            default:

            }
            colit++;

        }
        //rowit++;
        rowct++;
        //increase row count
    }

    System.out.println("Row Count:\t" + rowct);
    System.out.println("Column Count:\t" + colct);
    for (int i = 1; i <= rowct; i++) {
        for (int j = 1; j <= colct; j++) {
            System.out.println("a[" + i + "][" + j + "]=" + a[i][j] + "\n");
        }
    }
    try {
        DriverManager.registerDriver(new com.mysql.jdbc.Driver());
        conn = DriverManager.getConnection(dbURL, dbUser, dbPass);
        String append = "?, ?";
        String quest = ", ?";

        for (int j = 1; j <= colct; j++) {
            append += quest;
        }

        String crsql;
        String cappend = "`uid`,`doc_id`";
        for (int j = 1; j <= colct; j++) {
            cappend = cappend + ",`" + j + "`";
        }
        crsql = "CREATE TABLE IF NOT EXISTS `data" + userid + docid + "` (\n"
                + "`row_id` INT(11) NOT NULL AUTO_INCREMENT,\n" + "`uid` VARCHAR(50) NOT NULL,\n"
                + "`doc_id` INT(11) NOT NULL";
        System.out.println(crsql);

        for (int j = 1; j <= colct; j++) {
            System.out.println("j:\t" + (j));
            crsql = crsql + ",\n`" + (j) + "` VARCHAR(50)";
        }
        crsql += ",\nPRIMARY KEY (`row_id`)\n)";

        System.out.println(crsql);

        PreparedStatement cstmt = conn.prepareStatement(crsql);
        int c = cstmt.executeUpdate();

        String sql = "INSERT INTO data" + userid + docid + "(" + cappend + ")" + " values (" + append + ")";
        System.out.println("Append=\t" + append);
        PreparedStatement statement = conn.prepareStatement(sql);
        statement.setString(1, userid);
        statement.setInt(2, docid);
        for (int i = 1; i <= rowct; i++) {
            for (int j = 1; j <= (colct); j++) {
                statement.setString(j + 2, a[i][j]);
                System.out.println("j=" + (j) + "\ta[" + i + "][" + (j) + "]=" + a[i][j] + "\n");
            }
            System.out.println("\n");
            System.out.println("\nstatement:\t" + statement);
            int res = statement.executeUpdate();
        }
    } catch (SQLException ex) {
        Logger.getLogger(diagramInputServlet.class.getName()).log(Level.SEVERE, null, ex);
    }
    for (int i = 1; i <= rowct; i++) {
        for (int j = 1; j <= colct; j++) {
            System.out.println("a[" + i + "][" + j + "]=" + a[i][j] + "\n");
        }
    }
    System.out.println("Rowct:\t" + rowct + "\nColct:\t" + colct);
    @SuppressWarnings("UseOfObsoleteCollectionType")
    Hashtable<String, Object> style = new Hashtable<String, Object>();
    style.put(mxConstants.STYLE_FILLCOLOR, mxUtils.getHexColorString(Color.WHITE));
    style.put(mxConstants.STYLE_STROKEWIDTH, 1.5);
    style.put(mxConstants.STYLE_STROKECOLOR, mxUtils.getHexColorString(new Color(0, 0, 170)));
    style.put(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_ELLIPSE);
    style.put(mxConstants.STYLE_PERIMETER, mxConstants.PERIMETER_ELLIPSE);

    graph = new mxGraph();

    mxStylesheet stylesheet = graph.getStylesheet();
    stylesheet.putCellStyle("process", createProcessStyle());
    stylesheet.putCellStyle("object", createObjectStyle());
    stylesheet.putCellStyle("state", createStateStyle());
    stylesheet.putCellStyle("agent", createAgentLinkStyle());
    fr = new JFrame("Enterprise Architecture Diagram");

    fr.setSize(2000, 2000);
    graph.setMinimumGraphSize(new mxRectangle(0, 0, 1000, 1500));
    graph.setMaximumGraphBounds(new mxRectangle(0, 0, 2000, 2000));
    graph.setMinimumGraphSize(new mxRectangle(0, 0, 1000, 1000));

    double rech1 = 200;
    double rech2 = 200;
    double rech3 = 170;
    double rech3e = 180;
    double rech4 = 120;
    Object defaultParent = graph.getDefaultParent();

    graph.setConstrainChildren(true);
    graph.setExtendParents(true);
    graph.setExtendParentsOnAdd(true);
    graph.setDefaultOverlap(0);
    graph.setCellsMovable(true); // Moving cells in the graph. Note that an edge is also a cell.
    graph.setCellsEditable(true);
    graph.setCellsResizable(true); // Inhibit cell re-sizing.

    graph.getModel().beginUpdate();

    Object[] obj = new Object[100];
    int k = 1;
    for (int i = 2; i <= rowct; i++) {
        for (int j = 1; j <= 2; j++) {
            obj[k] = a[i][j];
            k++;
        }

    }

    //print debug info
    for (int l = 1; l <= (rowct * 2) - 2; l++) {
        System.out.println("obj[" + l + "]:\t" + obj[l]);
    }

    List<Object> list = new ArrayList<Object>();
    for (Object val : obj) {
        if (!list.contains(val)) {
            list.add(val);
        }
    }

    list.remove(null);
    list.toArray(new Object[0]);
    System.out.println("list:" + list);

    Object[] array = new Object[list.size()];
    list.toArray(array); // fill the array
    System.out.println("Array:\t" + Arrays.toString(array));

    Object[] gArray = new Object[array.length];
    String[] sArray = new String[array.length];

    for (int i = 0; i < array.length; i++) {
        sArray[i] = array[i].toString();
        if (sArray[i].contains("Database") || sArray[i].contains("Server") || sArray[i].contains("DATABASE")
                || sArray[i].contains("SERVER") || sArray[i].contains("DB")) {
            System.out.println("Object type");
            gArray[i] = graph.insertVertex(defaultParent, null, sArray[i], rech1, rech2, rech3, rech4,
                    "object");

        } else {
            System.out.println("Process type");
            gArray[i] = graph.insertVertex(defaultParent, null, sArray[i], rech1, rech2, rech3e, rech4,
                    "process");
        }
        rech1 += 100;
        rech2 += 100;
    }

    for (int i = 2; i <= rowct; i++) {

        if (a[i][3].equals("Two Way") || a[i][3].equals("TWO WAY") || a[i][3].equals("TwoWay")
                || a[i][3].equals("TWOWAY") || a[i][3].equals("2 Way") || a[i][3].equals("Two way")) {
            System.out.println("Double Edges");
            int l1 = 0, l2 = 0;
            for (int l = 1; l < gArray.length; l++) {
                System.out.println("gArray.toString=\t" + sArray[l]);
                System.out.println("gArray.length=\t" + sArray.length);
                if (sArray[l].equals(a[i][1])) {
                    l1 = l;
                    System.out.println("l2:\t" + l1);
                }
                if (sArray[l].equals(a[i][2])) {
                    l2 = l;
                    System.out.println("l2:\t" + l2);
                }
            }
            graph.insertEdge(defaultParent, null, a[i][4], gArray[l1], gArray[l2], "agent");
            graph.insertEdge(defaultParent, null, a[i][4], gArray[l2], gArray[l1], "agent");

        } else {
            System.out.println("Single Edges");
            int l1 = 0, l2 = 0;
            for (int l = 1; l < gArray.length; l++) {
                System.out.println("gArray.toString=\t" + sArray[l]);
                System.out.println("gArray.length=\t" + sArray.length);
                if (sArray[l].equals(a[i][1])) {
                    l1 = l;
                    System.out.println("l2:\t" + l2);
                }
                if (sArray[l].equals(a[i][2])) {
                    l2 = l;
                    System.out.println("l2:\t" + l2);
                }
            }
            graph.insertEdge(defaultParent, null, a[i][4], gArray[l1], gArray[l2], "agent");
        }
    }

    graph.setEnabled(true);

    graph.setAutoSizeCells(true);

    graph.getModel().endUpdate();

    graphComponent = new mxGraphComponent(graph);
    mxFastOrganicLayout layout = new mxFastOrganicLayout(graph);
    // define layout

    //set all properties
    layout.setMinDistanceLimit(1);
    //layout.setInitialTemp(5);
    //layout.setInitialTemp(10);
    //layout.setForceConstant(10);
    //layout.setDisableEdgeStyle(true);
    //layout graph
    //layout.execute(graph.getDefaultParent());
    // layout using morphing
    String fileWPath;

    graph.getModel().beginUpdate();
    try {
        layout.execute(graph.getDefaultParent());
    } finally {
        mxMorphing morph = new mxMorphing(graphComponent, 20, 1.2, 20);

        morph.addListener(mxEvent.DONE, new mxIEventListener() {

            @Override
            public void invoke(Object arg0, mxEventObject arg1) {
                graph.getModel().endUpdate();
                // fitViewport();
            }

        });

        BufferedImage image;
        image = mxCellRenderer.createBufferedImage(graph, null, 2, Color.WHITE, true, null);
        Document d = mxCellRenderer.createVmlDocument(graph, null, 1, Color.WHITE, null);
        pathToWeb = getServletContext().getRealPath(File.separator);
        System.out.println("pathtoweb:\t" + pathToWeb);
        fileWPath = pathToWeb + "genImg\\" + userid + docid + ".png";
        System.out.println("filewpath:\t" + fileWPath);
        //System.out.println(pathToWeb + userid + docid + ".svg");
        ImageIO.write(image, "PNG", new File(fileWPath));
        XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(
                new FileOutputStream(new File(pathToWeb + "genXML\\" + userid + docid + ".xml"))));
        encoder.writeObject(graph);
        encoder.close();
        morph.startAnimation();
    }

    graphComponent.setConnectable(false);
    fr.getRootPane().setBorder(BorderFactory.createMatteBorder(4, 4, 4, 4, Color.WHITE));
    // Inhibit edge creation in the graph.
    fr.getContentPane().add(graphComponent);

    //fr.setVisible(true);

    request.setAttribute("docidM", docid);
    request.setAttribute("useridM", userid);
    request.setAttribute("colCountM", colct);
    request.setAttribute("rowCountM", rowct);
    request.setAttribute("fileLinkM", fileWPath);
    request.setAttribute("pathToWebM", pathToWeb);
    System.out.println("Iteration Complete");

    getServletContext().getRequestDispatcher("/success.jsp").forward(request, response);

}

From source file:com.aurel.track.exchange.excel.ExcelImportBL.java

License:Open Source License

/**
 * Gets the string value of a cell//from w  w w.j  a va 2  s. co  m
 * 
 * @param cell
 * @return
 */
static String getStringCellValue(Cell cell) {
    try {
        int cellType = cell.getCellType();
        switch (cellType) {
        case Cell.CELL_TYPE_BLANK:
            return "";
        case Cell.CELL_TYPE_BOOLEAN:
            return String.valueOf(cell.getBooleanCellValue());
        case Cell.CELL_TYPE_ERROR:
            return String.valueOf(cell.getErrorCellValue());
        case Cell.CELL_TYPE_FORMULA:
            return cell.getCellFormula();
        case Cell.CELL_TYPE_NUMERIC:
            try {
                double doubleValue = cell.getNumericCellValue();
                int intValue = (int) doubleValue;
                double fracPart = doubleValue - intValue;
                if (Math.abs(fracPart) <= Double.MIN_VALUE) {
                    return String.valueOf(intValue);
                } else {
                    return String.valueOf(doubleValue);
                }
            } catch (Exception e) {
            }
        case Cell.CELL_TYPE_STRING:
            RichTextString richTextString = cell.getRichStringCellValue();
            if (richTextString != null) {
                return richTextString.getString();
            }
        }
    } catch (Exception e) {
        LOGGER.debug("Getting the string value failed with " + e.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
    }
    return "";
}

From source file:com.aurel.track.exchange.excel.ExcelImportBL.java

License:Open Source License

/**
 * Gets the Double value of a cell/*w  w w  . j  a  v a2  s.  c o  m*/
 * 
 * @param cell
 * @return
 */
private static Boolean getBooleanCellValue(Cell cell) throws ExcelImportInvalidCellValueException {
    Boolean booleanValue = null;
    int cellType = cell.getCellType();
    if (cellType == Cell.CELL_TYPE_BOOLEAN) {
        boolean boolCellValue = cell.getBooleanCellValue();
        booleanValue = new Boolean(boolCellValue);
    } else {
        if (cellType == Cell.CELL_TYPE_STRING) {
            RichTextString richTextString = cell.getRichStringCellValue();
            if (richTextString != null) {
                String stringValue = richTextString.getString();
                if (stringValue != null) {
                    stringValue = stringValue.trim();
                    if (!"".equals(stringValue)) {
                        if ("true".equalsIgnoreCase(stringValue)
                                || BooleanFields.TRUE_VALUE.equalsIgnoreCase(stringValue)) {
                            booleanValue = new Boolean(true);
                        } else {
                            if ("false".equalsIgnoreCase(stringValue)
                                    || BooleanFields.FALSE_VALUE.equalsIgnoreCase(stringValue)) {
                                booleanValue = new Boolean(false);
                            } else {
                                if (stringValue != null && !"".equals(stringValue.trim())) {
                                    throw new ExcelImportInvalidCellValueException(stringValue);
                                }
                            }
                        }
                    }
                }
            }
        } else {
            throw new ExcelImportInvalidCellValueException(getStringCellValue(cell));
        }
    }
    return booleanValue;
}

From source file:com.aurel.track.lucene.util.poi.XLSTextStripper.java

License:Open Source License

public XLSTextStripper(FileInputStream fis, String fileExtension) {
    try {// w w  w  . j  ava2  s  .  c om
        StringBuffer sb = new StringBuffer();
        Workbook workbook = null;
        if (LuceneFileExtractor.INDEXABLE_EXTENSIONS.XLS.equalsIgnoreCase(fileExtension)) {
            workbook = new HSSFWorkbook(fis);
        } else {
            if (LuceneFileExtractor.INDEXABLE_EXTENSIONS.XLSX.equalsIgnoreCase(fileExtension)) {
                workbook = new XSSFWorkbook(fis);
            }
        }
        if (workbook != null) {
            int numOfSheets = workbook.getNumberOfSheets();
            for (int i = 0; i < numOfSheets; i++) {
                Sheet sheet = workbook.getSheetAt(i);
                Iterator<Row> rowIterator = sheet.rowIterator();
                while (rowIterator.hasNext()) {
                    Row row = rowIterator.next();
                    Iterator<Cell> cellIterator = row.cellIterator();
                    while (cellIterator.hasNext()) {
                        Cell cell = cellIterator.next();
                        String cellStringValue = null;
                        if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) {
                            boolean booleanValue = cell.getBooleanCellValue();
                            cellStringValue = Boolean.toString(booleanValue);
                        } else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                            double doubleValue = cell.getNumericCellValue();
                            cellStringValue = Double.toString(doubleValue);
                        } else if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
                            cellStringValue = cell.getStringCellValue();
                        }
                        if (cellStringValue != null) {
                            sb.append(cellStringValue);
                            sb.append("\t");
                        }
                    }
                    sb.append("\n");
                }
            }
        }
        _text = sb.toString();
    } catch (Exception e) {
        LOGGER.error(ExceptionUtils.getStackTrace(e));
    }
}

From source file:com.b2international.snowowl.datastore.server.importer.ExcelUtilities.java

License:Apache License

private static String extractAsString(final Cell cell, final boolean formatNumber) {
    String value = "";

    if (cell == null) {
        return value;
    }//from   w w w. java2 s  .  c  o  m

    FormulaEvaluator formulaEvaluator = cell.getSheet().getWorkbook().getCreationHelper()
            .createFormulaEvaluator();

    int type = cell.getCellType();

    switch (type) {
    case Cell.CELL_TYPE_NUMERIC:
        if (formatNumber) {
            value = convertToString(cell.getNumericCellValue());
        } else {
            value = convertToStringWithoutFormat(cell.getNumericCellValue());
        }
        break;
    case Cell.CELL_TYPE_STRING:
        value = cell.getStringCellValue();
        break;
    case Cell.CELL_TYPE_FORMULA:
        CellValue cellValue = formulaEvaluator.evaluate(cell);
        value = cellValue.getStringValue(); //type should be checked
        break;
    case Cell.CELL_TYPE_BOOLEAN:
        value = Boolean.toString(cell.getBooleanCellValue());
        break;
    case Cell.CELL_TYPE_BLANK:
        //do nothing, sctId is null
        break;
    default:
        LOGGER.log(Level.SEVERE, "Unsupported cell type:" + type + " for cell: " + cell);
        break;
    }
    return null == value ? "" : value;
}

From source file:com.b2international.snowowl.snomed.core.refset.automap.XlsParser.java

License:Apache License

/**
 * @param cell//w w w . j av a2 s . c  o  m
 * @return the textual representation of the cell or empty string if the cell is empty (null)
 */
private String getStringValue(Cell cell) {
    String value = "";
    if (cell != null) {
        switch (cell.getCellType()) {
        case Cell.CELL_TYPE_STRING:
            value = cell.getRichStringCellValue().getString();
            break;
        case Cell.CELL_TYPE_NUMERIC:
            if (DateUtil.isCellDateFormatted(cell)) {
                value = cell.getDateCellValue().toString();
            } else {
                value = Integer.toString((int) cell.getNumericCellValue());
            }
            break;
        case Cell.CELL_TYPE_BOOLEAN:
            value = Boolean.toString(cell.getBooleanCellValue());
            break;
        case Cell.CELL_TYPE_FORMULA:
            value = cell.getCellFormula();
            break;
        }
    }
    return value;
}

From source file:com.b2international.snowowl.snomed.importer.net4j.SnomedSubsetImportUtil.java

License:Apache License

private String getStringValue(final Cell cell) {
    String value = "";

    //   empty cell
    if (cell == null) {
        return "";
    }//  w  ww  . ja va2s  .  com

    switch (cell.getCellType()) {
    case Cell.CELL_TYPE_STRING:
        value = cell.getRichStringCellValue().getString();
        break;
    case Cell.CELL_TYPE_NUMERIC:
        if (DateUtil.isCellDateFormatted(cell)) {
            value = cell.getDateCellValue().toString();
        } else {
            value = Integer.toString((int) cell.getNumericCellValue());
        }
        break;
    case Cell.CELL_TYPE_BOOLEAN:
        value = Boolean.toString(cell.getBooleanCellValue());
        break;
    case Cell.CELL_TYPE_FORMULA:
        value = cell.getCellFormula();
        break;
    }

    return value;
}

From source file:com.bayareasoftware.chartengine.ds.util.ExcelInference.java

License:Apache License

public static String getCellString(Cell cell, HSSFFormulaEvaluator eval, DateFormat dfmt) {
    if (cell == null) {
        return null;
    }// w ww . ja v a  2  s. c o  m
    String ret = null;
    eval.evaluate(cell);
    switch (cell.getCellType()) {
    case HSSFCell.CELL_TYPE_NUMERIC:
    case HSSFCell.CELL_TYPE_FORMULA: // ?
        if (isCellDateFormatted(cell)) {
            if (dfmt == null) {
                dfmt = new SimpleDateFormat("yyyy-MM-dd");
            }
            Date d = cell.getDateCellValue();
            if (d != null) {
                ret = dfmt.format(d);
            } else {
                ret = "";
            }
        } else {
            try {
                ret = "" + cell.getNumericCellValue();
            } catch (IllegalStateException ise) {
                int errVal = cell.getErrorCellValue();
                String formula = cell.getCellFormula();
                int cacheType = cell.getCachedFormulaResultType();
                throw new RuntimeException(ise.getMessage() + ": errVal=" + errVal + " formula='" + formula
                        + "' cacheType=" + cacheType);
            }
        }
        break;
    case HSSFCell.CELL_TYPE_BLANK:
        ret = null;
        break;
    case HSSFCell.CELL_TYPE_BOOLEAN:
        ret = "" + cell.getBooleanCellValue();
        break;
    case HSSFCell.CELL_TYPE_STRING:
    default:
        ret = cell.getRichStringCellValue().getString();
    }
    return ret;
}