如何使用jxl检查excel表中的列中的值是空的

时间:2014-07-17 05:25:34

标签: java excel jxl

我需要使用jxl检查excel表中列的值。如果前三列为空,则第四列不应为空,或者如果第四列为空,则所有三列都不应为空。

请使用jxl建议如何执行此操作。

1 个答案:

答案 0 :(得分:0)

Workbook workbook = Workbook.getWorkbook(new File("myfile.xls"));
Sheet sheet = workbook.getSheet(0);
for (int i = 0; i < sheet.getRows(); i++) {
    boolean c1Empty = sheet.getCell(0, i).getContents().isEmpty();
    boolean c2Empty = sheet.getCell(1, i).getContents().isEmpty();
    boolean c3Empty = sheet.getCell(2, i).getContents().isEmpty();
    boolean c4Empty = sheet.getCell(3, i).getContents().isEmpty();
    if (c1Empty && c2Empty && c3Empty && c4Empty) {
        throw new RuntimeException("If the first three columns are empty then the fourth column can not empty.");
    }
    // Redundant
    //if (c4Empty && c1Empty && c2Empty && c3Empty) {
    //    throw new RuntimeException("If the fourth column is empty then all the three columns should not be empty.");
    //}
}