String fileName = "F:\\4366.xlsx";
ExcelWriter writer = ExcelUtil.getWriter(fileName);
private static void merger(ExcelWriter writer) {//合并 选择范围至少要两个cell要不会报错//合并的开始列 ,最后一列int startCol = 5,lastCol = 10;//合并开始行 结束行int startRow = 1,endRow = 5;String content = "合并后写入的内容";//合并后设置样式CellStyle row0Style = writer.createRowStyle(0);//根据当前行进行合并 0-lastCol 列writer.merge(lastCol);//合并后写入内容writer.merge(lastCol,content);//合并后 设置表头样式writer.merge(lastCol,content,false);//选择合并范围后写入内容 并设置默认的 表头样式writer.merge(startRow,endRow,startCol,lastCol,content,true);//选择合并范围后写入内容 并设置样式;writer.merge(startRow, endRow, startCol,lastCol , content, row0Style);}
private static void setWorkbookWriteStyle(ExcelWriter writer) {//宋体 9号Font allfont = writer.createFont();allfont.setFontName("宋体");allfont.setFontHeightInPoints((short) 9);StyleSet sset = new StyleSet(writer.getWorkbook());sset.setAlign(HorizontalAlignment.LEFT, VerticalAlignment.CENTER);sset.setFont(allfont, false);writer.setStyleSet(sset);}
public static CellStyle rowStyle(ExcelWriter writer) {CellStyle row0Style = writer.createRowStyle(0);Font row0Font = writer.createFont();row0Font.setFontHeightInPoints((short) 18);row0Font.setFontName("宋体");row0Font.setBold(true);row0Style.setFont(row0Font);//设置对齐的格式 剧中row0Style.setAlignment(HorizontalAlignment.CENTER);//设置边框 有以下的格式
// NONE(0),
// THIN(1),
// MEDIUM(2),
// DASHED(3),
// DOTTED(4),
// THICK(5),
// DOUBLE(6),
// HAIR(7),
// MEDIUM_DASHED(8),
// DASH_DOT(9),
// MEDIUM_DASH_DOT(10),
// DASH_DOT_DOT(11),
// MEDIUM_DASH_DOT_DOT(12),
// SLANTED_DASH_DOT(13);row0Style.setBorderBottom(BorderStyle.DASH_DOT);row0Style.setBorderLeft(BorderStyle.DOTTED);row0Style.setBorderRight(BorderStyle.DOUBLE);row0Style.setBorderTop(BorderStyle.MEDIUM);//背景色row0Style.setFillBackgroundColor((short) 9888);//前景色row0Style.setFillForegroundColor((short) 9888);//设置填充方式row0Style.setFillPattern(FillPatternType.THICK_HORZ_BANDS);//设置数据格式row0Style.setDataFormat((short) 1);return row0Style;}
//每一行的数据 List<List<Object>> exportList = Lists.newArrayList();
//跳过行数
writer.passRows(3);
writer.write(exportList);
writer.flush();
writer.getOrCreateCell(x, y).setCellValue("这是一个测试");