如何使用java在Excel中使特定的单元格作为边框forms

我可以知道如何使用java在Excel中使特定单元格作为边框forms? 我只需要特定的单元格与表foramat。 参考:我已经附上屏幕截图了解更多详情。

在这里输入图像说明

我的代码:

try { int rowCount = 1; FileOutputStream fileOut = new FileOutputStream("poi-test.xls"); HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet(); HSSFRow row = null; HSSFCell cell = null; HSSFFont heading_caption_font = null; HSSFCellStyle heading_caption_style = null; workbook.setSheetName(0, "Ageing Report", HSSFWorkbook.ENCODING_COMPRESSED_UNICODE); heading_caption_font = workbook.createFont(); heading_caption_font.setFontHeightInPoints((short)12); heading_caption_font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); heading_caption_font.setFontName("Calibri"); heading_caption_style = workbook.createCellStyle(); heading_caption_style.setFont(heading_caption_font); row = sheet.createRow(rowCount); rowCount += 1; cell = row.createCell((short)3); cell.setCellValue("Aging Report on UN-acted (DETAILED)"); cell.setCellStyle(heading_caption_style); sheet.addMergedRegion(new Region(1, (short)3, 1, (short)4)); workbook.write(fileOut); fileOut.flush(); fileOut.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } 

我不能够得到reqeried输出:

下面的代码片段会为你做。

 Workbook wb = new HSSFWorkbook(); Sheet sheet = wb.createSheet("Ageing Report"); Row row = sheet.createRow(1); Cell cell = row.createCell(3); cell.setCellValue("Aging Report on UN-acted (DETAILED)"); CellRangeAddress region = new CellRangeAddress(1, 1, 3, 4); RegionUtil.setBorderBottom(CellStyle.BORDER_MEDIUM, region, sheet, wb); RegionUtil.setBorderTop(CellStyle.BORDER_MEDIUM, region, sheet, wb); RegionUtil.setBorderRight(CellStyle.BORDER_MEDIUM, region, sheet, wb); RegionUtil.setBorderLeft(CellStyle.BORDER_MEDIUM, region, sheet, wb); sheet.addMergedRegion(region);