简体   繁体   English

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

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

I need to check the values in columns in excel sheet using jxl.If the first three columns are empty then the fourth column should not empty or if the fourth column is empty then all the three columns should not be empty. 我需要使用jxl检查excel工作表中的列中的值。如果前三列为空,则第四列不应为空,或者如果第四列为空,则所有三列均不应为空。

Please suggest how to do this using jxl. 请提出使用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