在JAVA执行。
public static void main(String[] args) {
String excelFilePathTemp = "E:\\excel\\12313.xlsx";
try (FileInputStream fis = new FileInputStream(excelFilePathTemp);
Workbook workbook = new XSSFWorkbook(fis)) {
Sheet sheet = workbook.getSheetAt(0);
// 遍历每一行
for (Row row : sheet) {
// 遍历每个单元格
for (Cell cell : row) {
CellStyle cellStyle = cell.getCellStyle();
// 检查是否设置了边框
try {
if (cellStyle.getBorderTop() != BorderStyle.NONE ||
cellStyle.getBorderBottom() != BorderStyle.NONE ||
cellStyle.getBorderLeft() != BorderStyle.NONE ||
cellStyle.getBorderRight() != BorderStyle.NONE) {
System.out.println("cellStyle at row " + cell.getRowIndex() +
", column " + cell.getColumnIndex() +
" has a border.");
}
}catch (Exception t){
}
// 将 CellStyle 转换为 XSSFCellStyle
if (cellStyle instanceof XSSFCellStyle) {
XSSFCellStyle xssfCellStyle = (XSSFCellStyle) cellStyle;
// 检查是否设置了边框
try {
if (xssfCellStyle.getBorderTop() != BorderStyle.NONE ||
xssfCellStyle.getBorderBottom() != BorderStyle.NONE ||
xssfCellStyle.getBorderLeft() != BorderStyle.NONE ||
xssfCellStyle.getBorderRight() != BorderStyle.NONE) {
System.out.println("xssfCellStyle at row " + cell.getRowIndex() +
", column " + cell.getColumnIndex() +
" has a border.");
}
}catch (Exception t){
}
}
}
}
System.out.println("Top border style and color updated successfully.");
} catch (IOException e) {
e.printStackTrace();
}
} |