public static void readExpectSheetAndWriteCaseSheet(matchAndNotMatchExcelObject matchExcelResult, String filePath) {
try {
ArrayList<ExceptionObject> readExpcetSheet = new ArrayList<ExceptionObject>();
ArrayList<ReplyObject> matchExcelList = matchExcelResult.getMatchExcelList();
String fileType = filePath.substring(filePath.lastIndexOf(".") + 1, filePath.length());
InputStream stream = new FileInputStream(filePath);
// Workbook xssfWorkbook = null;
XSSFWorkbook xssfWorkbook = null;
if (fileType.equals("xls")) {
// xssfWorkbook = new HSSFWorkbook(stream);
} else if (fileType.equals("xlsx")) {
xssfWorkbook = new XSSFWorkbook(stream);
}
XSSFSheet xssfSheet = xssfWorkbook.getSheet("Sheet2");
// Sheet xssfSheet = xssfWorkbook.getSheet("Sheet2");
System.out.println("sheet2 lastRowNum = "+xssfSheet.getLastRowNum());
for (int rowNum = 2; rowNum <= xssfSheet.getLastRowNum(); rowNum++) {
if (rowNum == xssfSheet.getLastRowNum()) {
System.out.println("ssssss");
}
System.out.println("read sheet2 &&&&&&&&&&&& "+rowNum);
ExceptionObject exceptionObject = new ExceptionObject();
XSSFRow xssfRow = xssfSheet.getRow(rowNum);
exceptionObject.setInput(xssfRow.getCell(5).getStringCellValue());
XSSFCellStyle cellStyle = xssfRow.getCell(7).getCellStyle();
if (cellStyle.getFillForegroundXSSFColor()!=null) {
exceptionObject.setBkColor(cellStyle);
System.out.println(cellStyle.getFillForegroundXSSFColor().getARGBHex());
}else {
exceptionObject.setBkColor(null);
POI 设置和获取excel单元格格式
最新推荐文章于 2022-08-30 19:21:27 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)