gpt4 book ai didi

java - 如何使用java在Excel中将特定单元格设置为边框形式

转载 作者:行者123 更新时间:2023-11-30 03:55:02 26 4
gpt4 key购买 nike

我可以知道如何使用java在Excel中将特定单元格作为边框形式吗?我只需要具有表格格式的特定单元格。引用:我附上了屏幕截图以了解更多详细信息。

enter image description here

我的代码:

 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();
}

我无法获得所需的输出:

最佳答案

下面的代码片段将为您完成。

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);

关于java - 如何使用java在Excel中将特定单元格设置为边框形式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23442866/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com