/**
* 给合并单元格加边框
* @throws IOException
*/
public static void border() throws IOException {
CellRangeAddress CellRangeAddress1 = new CellRangeAddress(5,6,3,4);
InputStream input = new FileInputStream(new File("d:/q1.et"));
HSSFWorkbook workbook = new HSSFWorkbook(input);
HSSFSheet sheet = workbook.getSheet("qqq");
sheet.addMergedRegion(CellRangeAddress1);//合并单元格
RegionUtil.setBorderLeft(1, CellRangeAddress1, sheet);
RegionUtil.setBorderBottom(1, CellRangeAddress1, sheet);
RegionUtil.setBorderRight(1, CellRangeAddress1, sheet);
RegionUtil.setBorderTop(1, CellRangeAddress1, sheet);
//给合并的单元格加边框
FileOutputStream output = new FileOutputStream(new File("d:/q1.et"));
workbook.write(output);
if (output != null) {
try {
output.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* 给指定单元格加边框
* @throws IOException
*/
public static void cellBorder() throws IOException {
HSSFWorkbook workbook=new HSSFWorkbook(); // 定义一个新的工作簿
Sheet sheet=workbook.createSheet("第一个Sheet页"); // 创建第一个Sheet页
Row row=sheet.createRow(0); // 创建一个行
Cell cell=row.createCell(6); // 创建一个单元格
cell.setCellValue(4);
HSSFCellStyle cellStyle = workbook.createCellStyle();
// 设置单元格边框
cellStyle.setBorderBottom(BorderStyle.DOTTED); //下边框
cellStyle.setBorderLeft(BorderStyle.THIN);//左边框
cellStyle.setBorderTop(BorderStyle.DOTTED);//上边框
cellStyle.setBorderRight(BorderStyle.THIN);//右边框
cell.setCellStyle(cellStyle);
FileOutputStream output = new FileOutputStream(new File("d:/1111.et"));
workbook.write(output);
if (output != null) {
try {
output.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
poi3.17excel加边框
最新推荐文章于 2025-07-01 11:22:45 发布