使用HSSFSheet类的方法即可:// Merge first row and column from 0 to maxColumnNum:
sheet.addMergedRegion(new Region(0, (short)0, 0, (short)maxColumnNum));可以自定义自己的Region来设置想合并的单元格
sheet.addMergedRegion(new Region(0, (short)0, 0, (short)maxColumnNum));可以自定义自己的Region来设置想合并的单元格
HSSFSheet sheet = wb.createSheet("new sheet");
HSSFRow row = sheet.createRow((short) 1);
HSSFCell cell = row.createCell((short) 1);
cell.setCellValue("This is a test of merging");
sheet.addMergedRegion(new Region(1,(short)1,1,(short)2));//指定合并区域
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
合并区域是分别指定起始和终了的列和行,都是从0开始
HSSFRegionUtil.setBorderBottom( borderMediumDashed,region, sheet1, wb );
HSSFRegionUtil.setBorderTop( borderMediumDashed,
region, sheet1, wb );
HSSFRegionUtil.setBorderLeft( borderMediumDashed,
region, sheet1, wb );
HSSFRegionUtil.setBorderRight( borderMediumDashed,
region, sheet1, wb );
HSSFRegionUtil.setBottomBorderColor(HSSFColor.AQUA.index, region, sheet1, wb);
HSSFRegionUtil.setTopBorderColor(HSSFColor.AQUA.index, region, sheet1, wb);
HSSFRegionUtil.setLeftBorderColor(HSSFColor.AQUA.index, region, sheet1, wb);
HSSFRegionUtil.setRightBorderColor(HSSFColor.AQUA.index, region, sheet1, wb); // Shows some usages of HSSFCellUtil
HSSFCellStyle style = wb.createCellStyle();
style.setIndention((short)4);
HSSFCellUtil.createCell(row, 8, "This is the value of the cell", style);
HSSFCell cell2 = HSSFCellUtil.createCell( row2, 8, "This is the value of the cell");
HSSFCellUtil.setAlignment(cell2, wb, HSSFCellStyle.ALIGN_CENTER);我根据官网的代码试了一下,需要一个CLASS,我也导进去了。COMMON的LANG也IMPORT了,但是还有错,也不显示错误。
你要的代码这里都有.顺便请各位看一下这个贴子,也是关于POI的.
http://community.csdn.net/Expert/topic/3706/3706109.xml?temp=.3011286