public static HashSet<String> getFlgValFromCell(Workbook wb, Sheet s){
Iterator<Row> rows = s.iterator;
HashSet<String> set = new HashSet<>();
while(rows.hasNext()){
Row row = rows.next();
Iterator<Cell> cells = row.iterator();
while(cells.hasNext()){
Cell cell = cells.next();
Font font = wb.getFontAt(cell.getCellStyle().getFontIndexAsInt());
if(font instanceof XSSFFont) {
XSSFFont xssfFont = (XSSFFont) font;
if(xssfFont!=null){
XSSFColor xssfColor = xssfFont.getXSSFColor();
if (xssfColor != null) {
byte[] colorRgb = xssfColor.getRGB();
//根据字体的rgb,判断字体颜色
if(colorRgb[0] == -1 && colorRgb[1] == 0 && colorRgb[2] == 0) {
set.add(String.valueOf(ExcelDealBase.getValue(cell)));
}
}
}
} else if (font instanceof HSSFFont){
if(10 == wb.getFontAt(cell.getCellStyle().getFontIndexAsInt()).getColor()){
set.add(String.valueOf(ExcelDealBase.getValue(cell)));
}
}
}
}
return set;
}
java获取excel sheet页所有红色文字内容
最新推荐文章于 2023-09-25 15:24:21 发布