springboot poi多sheet excel导出
从hbase 查出数据 一个设备有多个参数 每个参数的数据为一个sheet 仅做记录
/**
* 输出Excel文档
* @param workbook
* @param resources 源数据
* @param headerNames 表头
* @param sheetName 表格名
* @param columnNum 列数量
* @param sheetNum 页码(sheet页码)
* @throws IOException
*/
public static void writeExcel(HSSFWorkbook workbook,
List<String[]> resources,
String[] headerNames,
String sheetName,
Integer columnNum,
Integer sheetNum) throws IOException {
// 创建表格
HSSFSheet sheet = workbook.createSheet();
sheet.setDefaultRowHeightInPoints(13);//默认宽度
workbook.setSheetName(sheetNum, sheetName);
// 设置列宽,根据
for(int i=0; i<=columnNum; i++){
sheet.setColumnWidth(i, 6000);
}
/*
* 创建合并区域
* CellRangeAddress(int 首行, int 最后一行, int 首列, int 最后一列);
*/
CellRangeAddress add = new CellRangeAddress(0, 0, 0, columnNum);
// 将创建的合并区域设置到表格中.
sheet.addMergedRegion(add);
// 创建行
Row header = sheet.createRow(0);
// 创建单元格. 合并后的单元格,编号合并.
//设置样式
CellStyle titleStyle = workbook.createCellStyle();
Font titlefont = workbook.createFont();
titlefont.setFontName("黑体");
//titlefont.setColor(IndexedColors.VIOLET.index);
titlefont.setFontHeightInPoints((short)20);
titlefont.setBold(true);
titleStyle.setFont(titlefont);
titleStyle.setAlignment(HorizontalAlignment.CENTER);
Cell c = header.createCell(0);
c.setCellValue(sheetName);
c.setCellStyle(titleStyle);
c = header.createCell(columnNum);
// 编写表头
// 定义表头的样式
CellStyle headerStyle = workbook.createCellStyle();
Font font = workbook.createFont();
font.setFontName("宋体");
//font.setColor(IndexedColors.VIOLET.index);
font.setFontHeightInPoints((short)16);
headerStyle.setFont(font);
headerStyle.setAlignment(HorizontalAlignment.CENTER);
// 设置单元格样式
Row headerRow = sheet.createRow(1);
for (int i = 0; i < headerNames.length; i++) {
Cell cell = headerRow.createCell(i);
// 设置单元格样式
cell.setCellStyle