import org.apache.poi.ss.usermodel
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
// Assume this method is wrapped in a class
public static void parseFile(){
// File Path has a .xls extension
FileInputStream file = new FileInputStream(filePath);
HSSFWorkbook wb = new HSSFWorkbook(file);
HSSFSheet sheet = wb.getSheetAt(0);
for(int rn = sheet.getFirstRowNum(); rn <= sheet.getLastRowNum(); rn++){
HSSFRow row = sheet.getRow(rn);
for(int cn = 0; cn < row.getLastCellNum(); cn++){
HSSFCell cell = row.getCell(cn);
//This is apache's color
HSSFColor color = cell.getCellStyle().getFillBackgroundColorColor;
// Excel entire row is red and it is not entering here.
if(color.equals(IndexedColors.RED)){
System.out.println("I made it here!");
cn++;
continue;
}
}
}
}
该文件处理得很好,但它不会进入我的“if 语句”。我做错了吗?这可以用 xls 文件完成吗?我看到了 xlsx 的示例,但我没有看到 xls 的任何示例。谢谢!