繁体   English   中英

如何使用jxl在Excel工作表中检查列中的值是否为空

[英]How to check the values in columns are empty in excel sheet using jxl

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

请提出使用jxl的方法。

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.");
    //}
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM