java数据导出成Excel文件
Posted dawn-and-night
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java数据导出成Excel文件相关的知识,希望对你有一定的参考价值。
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("综合信息");
HSSFRow row = sheet.createRow(0);
HSSFCell c0 = row.createCell(0);
//设置格式
HSSFCellStyle cellStyle = workbook.createCellStyle();
HSSFFont font = workbook.createFont();
font.setFontHeightInPoints((short) 12);
font.setFontName("黑体");
cellStyle.setFont(font);
cellStyle.setAlignment(CellStyle.ALIGN_CENTER);
cellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
c0.setCellStyle(cellStyle);
c0.setCellValue(new HSSFRichTextString(startTime1));
sheet.addMergedRegion(new CellRangeAddress(0,0,0,7));
HSSFRow row1 = sheet.createRow(1);
HSSFCell c1 = row1.createCell(0);
c1.setCellValue(new HSSFRichTextString("门诊人数"));
HSSFCell c3 = row1.createCell(2);
c3.setCellValue(new HSSFRichTextString("门急诊总人数"));
HSSFCell c4 = row1.createCell(4);
c4.setCellValue(new HSSFRichTextString("出诊医生总人数"));
HSSFCell c5 = row1.createCell(6);
c5.setCellValue(new HSSFRichTextString("医生平均门急诊量"));
HSSFRow row2 = sheet.createRow(2);
HSSFCell c2 = row2.createCell(0);
c2.setCellValue(new HSSFRichTextString("急诊人数"));
HSSFRow row3 = sheet.createRow(3);
HSSFCell c6 = row3.createCell(0);
c6.setCellValue(new HSSFRichTextString("处方数量"));
HSSFCell c7 = row3.createCell(2);
c7.setCellValue(new HSSFRichTextString("最大处方"));
HSSFCell c8 = row3.createCell(4);
c8.setCellValue(new HSSFRichTextString("平均处方金额"));
HSSFCell c9 = row3.createCell(6);
c9.setCellValue(new HSSFRichTextString("医生平均处方数量"));
HSSFRow row4 = sheet.createRow(4);
HSSFCell c10 = row4.createCell(0);
c10.setCellValue(new HSSFRichTextString("处方总额"));
HSSFCell c11 = row4.createCell(2);
c11.setCellValue(new HSSFRichTextString("最小处方"));
HSSFRow row5 = sheet.createRow(5);
HSSFCell c12 = row5.createCell(0);
c12.setCellValue(new HSSFRichTextString("入院人数"));
HSSFCell c13 = row5.createCell(2);
c13.setCellValue(new HSSFRichTextString("出院人数"));
HSSFCell c14 = row5.createCell(4);
c14.setCellValue(new HSSFRichTextString("在院人数"));
HSSFCell c15 = row5.createCell(6);
c15.setCellValue(new HSSFRichTextString("危重人数"));
HSSFRow row6 = sheet.createRow(6);
HSSFCell c16 = row6.createCell(0);
c16.setCellValue(new HSSFRichTextString("额定床位"));
HSSFCell c17 = row6.createCell(2);
c17.setCellValue(new HSSFRichTextString("使用床位"));
HSSFCell c18 = row6.createCell(4);
c18.setCellValue(new HSSFRichTextString("床位使用率"));
HSSFCell c19 = row6.createCell(6);
c19.setCellValue(new HSSFRichTextString("死亡人数"));
HSSFRow row7 = sheet.createRow(7);
HSSFCell c20 = row7.createCell(0);
c20.setCellValue(new HSSFRichTextString("医疗收入"));
HSSFCell c21 = row7.createCell(2);
c21.setCellValue(new HSSFRichTextString("药品收入"));
HSSFCell c22 = row7.createCell(4);
c22.setCellValue(new HSSFRichTextString("其他收入"));
HSSFCell c23 = row7.createCell(6);
c23.setCellValue(new HSSFRichTextString("合计收入"));
HSSFRow row8 = sheet.createRow(8);
HSSFCell c24 = row8.createCell(0);
c24.setCellValue(new HSSFRichTextString("今日手术"));
HSSFCell c25 = row8.createCell(1);
c25.setCellValue(new HSSFRichTextString("安排数量"));
HSSFCell c26 = row8.createCell(4);
c26.setCellValue(new HSSFRichTextString("明日手术安排数量"));
HSSFRow row9 = sheet.createRow(9);
HSSFCell c27 = row9.createCell(1);
c27.setCellValue(new HSSFRichTextString("实际数量"));
for (int i=0;i<list1.size();i++)
row1.createCell(1).setCellValue(list1.get(0));
row1.createCell(3).setCellValue(sum1);
row1.createCell(5).setCellValue(list1.get(2));
row1.createCell(7).setCellValue(avg1);
row2.createCell(1).setCellValue(list1.get(1));
row3.createCell(1).setCellValue(list1.get(3));
row3.createCell(3).setCellValue(list1.get(4));
row3.createCell(5).setCellValue(avg2);
row3.createCell(7).setCellValue(avg3);
row4.createCell(1).setCellValue(list1.get(5));
row4.createCell(3).setCellValue(list1.get(6));
row5.createCell(1).setCellValue(list1.get(7));
row5.createCell(3).setCellValue(list1.get(8));