| | |
| | | Sheet sheet = sxssfWorkbook.createSheet(sheetName); |
| | | // 创建列头 |
| | | sheet.createFreezePane(0, 1); |
| | | Row header = sheet.createRow(0); |
| | | CellStyle hstyle = configHeaderCellStatic(sxssfWorkbook); |
| | | CellStyle rowStyle = configDataCellStatic(sxssfWorkbook); |
| | | for (int i = 0; i < dataList.size(); i++) { |
| | | Cell cell = header.createCell(i); |
| | | cell.setCellValue(dataList.get(i).get(Constants.ZERO)); |
| | | // 列宽设置 |
| | | sheet.setColumnWidth(i, dataList.get(i).get(Constants.ZERO).length() * 2 * 256); |
| | | // 设置列头单元格 |
| | | cell.setCellStyle(hstyle); |
| | | } |
| | | |
| | | //总行数 |
| | | Integer rowSize = dataList.get(Constants.ZERO).size(); |
| | | //总列数 |
| | | Integer columnSize = dataList.size(); |
| | | for (int i = 1; i < rowSize; i++) { |
| | | Row row = sheet.createRow(i); |
| | | for (int j = 0; j < columnSize; j++) { |
| | | List<String> rowList = dataList.get(i); |
| | | for (int j = 0; j < rowList.size(); j++) { |
| | | Cell cell = row.createCell(j); |
| | | cell.setCellValue(dataList.get(j).get(i)); |
| | | if(i==0&&j==0){ |
| | | cell.setCellValue("数据日期"); |
| | | }else{ |
| | | cell.setCellValue(rowList.get(j)); |
| | | } |
| | | |
| | | if(i==0){ |
| | | sheet.setColumnWidth(i, rowList.get(i).length() * 2 * 256); |
| | | // cell.setCellStyle(hstyle); |
| | | } |
| | | if(i==0 || j==0){ |
| | | cell.setCellStyle(hstyle); |
| | | }else{ |
| | | cell.setCellStyle(rowStyle); |
| | | } |
| | | } |
| | | } |
| | | sxssfWorkbook.write(os); |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | private static CellStyle configHeaderCellStatic (SXSSFWorkbook workbook) { |
| | | CellStyle style = workbook.createCellStyle(); |
| | | style.setAlignment(HorizontalAlignment.CENTER); |
| | |
| | | style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); |
| | | // 字体 |
| | | Font font = workbook.createFont(); |
| | | font.setFontHeightInPoints((short) 12); |
| | | font.setFontHeightInPoints((short) 10); |
| | | style.setFont(font); |
| | | // 设置边框 |
| | | configCellBorder(style); |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 配置数据单元格 |
| | | */ |
| | | private static CellStyle configDataCellStatic (SXSSFWorkbook workbook ) { |
| | | CellStyle configDataCellStyle = workbook.createCellStyle(); |
| | | configDataCellStyle.setAlignment(HorizontalAlignment.CENTER); |
| | | configDataCellStyle.setVerticalAlignment(VerticalAlignment.CENTER); |
| | | // 设置背景 |
| | | // configDataCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); |
| | | // configDataCellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); |
| | | // 字体 |
| | | Font font = workbook.createFont(); |
| | | font.setFontHeightInPoints((short) 10); |
| | | |
| | | configDataCellStyle.setFont(font); |
| | | // 边框 |
| | | configCellBorder(configDataCellStyle); |
| | | configDataCellStyle.setWrapText(true); |
| | | return configDataCellStyle; |
| | | } |
| | | |
| | | } |