如何读取Excel单元格中有太多的Java中的空值...? [英] How to read Excel cell having null values too in Java...?

查看:1116
本文介绍了如何读取Excel单元格中有太多的Java中的空值...?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Apache POI 3.6。我有一列是的空白。我希望能够读取它,然后移动到下一列。即使我能解决 NullPointerException异常的问题,我无法进入下一个单元格。

I'm using Apache POI 3.6. I've a column which is blank. I would like to be able to read it and then move to the next column. Even if I could resolve the NullPointerException problem I could not get to the next cell.

下面是我的code片断:

Here's my code snippet :

HSSFCell cell = row.getCell(c);
String value = null;

switch (cell.getCellType()) {

    case HSSFCell.CELL_TYPE_FORMULA:
        value = "FORMULA value=" + cell.getCellFormula();
        break;

    case HSSFCell.CELL_TYPE_NUMERIC:
        value = "NUMERIC value=" + cell.getNumericCellValue();
        break;

    case HSSFCell.CELL_TYPE_STRING:
        value = "STRING value=" + cell.getStringCellValue();
        break;

    case HSSFCell.CELL_TYPE_BLANK:
        value="";
        break;

    case HSSFCell.CELL_TYPE_ERROR:
        value="error";
        break;

    default:
        break;
}

System.out.println("CELL col=" + cell.getColumnIndex() + " VALUE=" + value);

如何解决我的问题?

How can I resolve my problem?

推荐答案

好了,你可以在你的开关语句之前检查空,或者你可以改变你做哪些来电row.getCell。检查的Javadoc POI有两种形式,第一种是你用的是什么,第二个有一个额外的参数,类型Row.MissingCellPolicy,在那里你可以通过将自动地转化空细胞为空白的值。

Well, you could check for null before your switch statement, or you could change which call to row.getCell you make. Checking the Javadoc for POI there are 2 forms, the first is what you are using, the second has an additional parameter, of the type Row.MissingCellPolicy, where you can pass a value that would automagically transform null cells into blanks.

这篇关于如何读取Excel单元格中有太多的Java中的空值...?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆