简体   繁体   中英

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.

Please suggest how to do this using 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.");
    //}
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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