仅供参考,有看不懂的地方@我
// 声明一个工作薄 XSSFWorkbook workbook = new XSSFWorkbook(); // 生成一个表格 XSSFSheet sheet = workbook.createSheet("sheet"); // 设置表格默认列宽度为15个字节 //sheet.setDefaultColumnWidth((short) 20); sheet.setColumnWidth(0, 10000); sheet.setColumnWidth(1, 3000); sheet.setColumnWidth(2, 5000); sheet.setColumnWidth(3, 5000); sheet.setColumnWidth(4, 5000); // 产生表格标题行 XSSFRow row = sheet.createRow(0); XSSFCell cell = row.createCell(0); cell.setCellValue("地域"); XSSFCell cell1 = row.createCell(1); cell1.setCellValue("RSRP");
//合并表格 sheet.addMergedRegion(new CellRangeAddress(0, 0, 1, 9)); XSSFCell cell2 = row.createCell(2); cell2.setCellValue("CQI"); sheet.addMergedRegion(new CellRangeAddress(0, 0, 10, 18)); row = sheet.createRow(2); sheet.addMergedRegion(new CellRangeAddress(0, 2, 0, 0)); for(int i=1;i<19;i++){ XSSFCell cell9 = row.createCell(i); if(i%3==1) { cell9.setCellValue("总里程"); }else if(i%3==2){ cell9.setCellValue("覆盖里程"); }else{ cell9.setCellValue("覆盖率"); } } int i = 3;
// 赋值 for(Map map:list){ row = sheet.createRow(i); row.createCell(0).setCellValue(map.get("NAME").toString()); row.createCell(1).setCellValue(map.get("ZTOTAL_COUNT").toString()); row.createCell(2).setCellValue(map.get("ZWEAKCOUNT").toString()); row.createCell(3).setCellValue(map.get("ZRATIO").toString()); row.createCell(4).setCellValue(map.get("GTOTAL_COUNT").toString()); row.createCell(5).setCellValue(map.get("GWEAKCOUNT").toString()); row.createCell(6).setCellValue(map.get("GRATIO").toString()); row.createCell(7).setCellValue(map.get("UTOTAL_COUNT").toString()); row.createCell(8).setCellValue(map.get("UWEAKCOUNT").toString()); row.createCell(9).setCellValue(map.get("URATIO").toString()); row.createCell(10).setCellValue(map.get("ZZTOTAL_COUNT").toString()); row.createCell(11).setCellValue(map.get("ZZWEAKCOUNT").toString()); row.createCell(12).setCellValue(map.get("ZZRATIO").toString()); row.createCell(13).setCellValue(map.get("GGTOTAL_COUNT").toString()); row.createCell(14).setCellValue(map.get("GGWEAKCOUNT").toString()); row.createCell(15).setCellValue(map.get("GGRATIO").toString()); row.createCell(16).setCellValue(map.get("UUTOTAL_COUNT").toString()); row.createCell(17).setCellValue(map.get("UUWEAKCOUNT").toString()); row.createCell(18).setCellValue(map.get("UURATIO").toString()); i++; } return workbook;