HSSFCellStyle 设置边框
时间: 2023-07-04 20:06:07 浏览: 201
HSSFCellStyle 可以通过 setBorderXXX 方法设置单元格的边框,其中 XXX 可以是 Top、Bottom、Left、Right 等。
下面是一个示例代码,设置单元格的上、下、左、右边框为实线:
```
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("Sheet1");
HSSFRow row = sheet.createRow(0);
HSSFCell cell = row.createCell(0);
// 创建单元格样式
HSSFCellStyle style = workbook.createCellStyle();
// 设置边框样式
style.setBorderTop(BorderStyle.THIN);
style.setBorderBottom(BorderStyle.THIN);
style.setBorderLeft(BorderStyle.THIN);
style.setBorderRight(BorderStyle.THIN);
// 应用样式到单元格
cell.setCellStyle(style);
// 写入数据到单元格
cell.setCellValue("Hello World!");
// 保存文件
FileOutputStream out = new FileOutputStream("workbook.xlsx");
workbook.write(out);
out.close();
```
在上面的代码中,我们创建了一个 HSSFCellStyle 对象,然后设置了其上、下、左、右边框为实线。最后将该样式应用到单元格上,并将数据写入单元格中。最后将工作簿写出到文件中。
阅读全文
相关推荐


















