添加边框合并单元格在Excel中的Apache POI的Java? [英] Add border to merged cells in excel Apache poi java.?
本文介绍了添加边框合并单元格在Excel中的Apache POI的Java?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用Apache POI,我需要把边框的单元格区域或合并区域。我合并将细胞与三行和五列。但我不能够边框添加到它。所以,我该怎么做呢?
I'm using Apache POI and I need to put a border in a range of cells or merged region. I am merging the cells with three rows and five columns. But I am not able to add the border to it. So how do I do this?
推荐答案
我的解决办法是通过自己的立场,以合并的单元格,然后创建一个单元格(参考合并单元格的第一个块)分配一个值,然后设置边境throught的<一个href=\"http://poi.apache.org/apidocs/org/apache/poi/ss/util/class-use/CellRangeAddress.html\">HSSFRegionUtil
My solution was to merge the cells by their positions, then created a cell (reference to the first block of the merged cells) to assign a value and then set the border throught the HSSFRegionUtil
// Merges the cells
CellRangeAddress cellRangeAddress = new CellRangeAddress(start, start, j, j + 1);
sheet.addMergedRegion(cellRangeAddress);
// Creates the cell
Cell cell = CellUtil.createCell(row, j, entry.getKey());
// Sets the borders to the merged cell
HSSFRegionUtil.setBorderTop(CellStyle.BORDER_MEDIUM, cellRangeAddress, sheet, workbook);
HSSFRegionUtil.setBorderLeft(CellStyle.BORDER_MEDIUM, cellRangeAddress, sheet, workbook);
HSSFRegionUtil.setBorderRight(CellStyle.BORDER_MEDIUM, cellRangeAddress, sheet, workbook);
HSSFRegionUtil.setBorderBottom(CellStyle.BORDER_THIN, cellRangeAddress, sheet, workbook);
这篇关于添加边框合并单元格在Excel中的Apache POI的Java?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文