[英]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.