POI操作
1、设置列宽度
HSSFWorkbook workbook = new HSSFWorkbook(); Sheet sheet = workbook.createSheet(); sheet.setColumnWidth(0, 10 * 256); sheet.setColumnWidth(1, 15 * 256); sheet.setColumnWidth(2, 40 * 256); sheet.setColumnWidth(3, 40 * 256);
2、合并单元格
CellRangeAddress region = new CellRangeAddress(0, 0, 1, 2); //起始行,结束行,起始列,结束列 sheet.addMergedRegion(region);
3、单元格居中
CellStyle cellStyle = workbook.createCellStyle(); cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); cell.setCellStyle(cellStyle);
4、内容换行
//1、内容加上换行符"\n" //2、单元格加上换行格式 HSSFWorkbook workbook = new HSSFWorkbook(); Sheet sheet = workbook.createSheet(); HSSFCellStyle cs = workbook.createCellStyle(); // 换行的关键,自定义单元格内容换行规则 cs.setWrapText(true); cell6.setCellStyle(cs);