java操作poi的excel表格的线条怎么变成黑色?

excelJava

1个回答

写回答

houyixuan

2026-02-07 15:55

+ 关注

excel
excel

你跑下下面的代码试下吧:public Testexcel(){ createexcelFile(); } private void createexcelFile() { HSSFWorkbook hwb = new HSSFWorkbook(); HSSFSheet sheet = hwb.createSheet(test sheet); //创建一个样式 HSSFCellStyle style = hwb.createCellStyle(); //设置边框样式 style.setBorderTop(HSSFCellStyle.BORDER_THIN); style.setBorderBottom(HSSFCellStyle.BORDER_THIN); style.setBorderLeft(HSSFCellStyle.BORDER_THIN); style.setBorderRight(HSSFCellStyle.BORDER_THIN); //设置边框颜色 style.setTopBorderColor(HSSFColor.BLACK.index); style.setBottomBorderColor(HSSFColor.BLACK.index); style.setLeftBorderColor(HSSFColor.BLACK.index); style.setRightBorderColor(HSSFColor.BLACK.index); for(int j=0;j5;j++){ HSSFRow row = sheet.createRow(j); for(int i=0;i10;i++){ HSSFCell cell = row.createCell(i); cell.setcellStyle(style); cell.setcellValue(j+*+i); } } File file = new File(./test.xls); try { FileOutputStream fos = new FileOutputStream(file); hwb.write(fos); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }

举报有用(0分享收藏

Copyright © 2025 IZhiDa.com All Rights Reserved.

知答 版权所有 粤ICP备2023042255号