EXCEL导出功能
@RequestMapping(value = "exportexcle")
public void ExportExcle(String years, HttpServletResponse response) {
List<Calculus> list = calculusDao.getCalListByYear(years);
Calendar cal = Calendar.getInstance();
try {
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = null;
if (StringUtils.isEmpty(years)) {
sheet = workbook.createSheet("太极实业综合党支部“微积分”制考核党员" + String.valueOf(cal.get(Calendar.YEAR)) + "年度积分管理表");
} else {
sheet = workbook.createSheet("太极实业综合党支部“微积分”制考核党员" + years + "年度积分管理表");
}
sheet.setColumnWidth(0, 5 * 256);
sheet.setColumnWidth(1, 10 * 256);
sheet.setColumnWidth(2, 15 * 256);
sheet.setColumnWidth(3, 15 * 256);
sheet.setColumnWidth(4, 15 * 256);
sheet.setColumnWidth(5, 20 * 256);
sheet.setColumnWidth(6, 15 * 256);
sheet.setColumnWidth(7, 15 * 256);
sheet.setColumnWidth(8, 15 * 256);
sheet.setColumnWidth(9, 20 * 256);
sheet.setColumnWidth(10, 15 * 256);
sheet.setColumnWidth(11, 15 * 256);
sheet.setColumnWidth(12, 15 * 256);
sheet.setColumnWidth(13, 15 * 256);
HSSFRow oneRow = sheet.createRow(0);
HSSFCell a0 = oneRow.createCell(0);
if (StringUtils.isEmpty(years)) {
a0.setCellValue("太极实业综合党支部“微积分”制考核党员" + String.valueOf(cal.get(Calendar.YEAR)) + "年度积分管理表");
} else {
a0.setCellValue("太极实业综合党支部“微积分”制考核党员" + years + "年度积分管理表");
}
HSSFRow twoRow = sheet.createRow(1);
HSSFCell b0 = twoRow.createCell(0);
b0.setCellValue("(每名党员年度民主测议得分×15%)");
HSSFRow threeRow = sheet.createRow(2);
HSSFCell c0 = threeRow.createCell(0);
c0.setCellValue("排名");
HSSFCell c1 = threeRow.createCell(1);
c1.setCellValue("姓名");
HSSFCell c2 = threeRow.createCell(2);
c2.setCellValue("积分项");
HSSFCell c3 = threeRow.createCell(13);
c3.setCellValue("最终年度得分");
HSSFRow fourRow = sheet.createRow(3);
HSSFCell d0 = fourRow.createCell(2);
d0.setCellValue("基础分 (70分)");
HSSFCell d1 = fourRow.createCell(5);
d1.setCellValue("年度民主测评");
HSSFCell d2 = fourRow.createCell(7);
d2.setCellValue("创优积分 ( 上不封顶)");
HSSFCell d3 = fourRow.createCell(10);
d3.setCellValue("扣分项 ( 扣完为止)");
HSSFRow fiveRow = sheet.createRow(4);
HSSFCell e3 = fiveRow.createCell(2);
e3.setCellValue("上半年扣减");
HSSFCell e4 = fiveRow.createCell(3);
e4.setCellValue("下半年扣减");
HSSFCell e5 = fiveRow.createCell(4);
e5.setCellValue("年度最终得分)");
HSSFCell e6 = fiveRow.createCell(5);
e6.setCellValue("年度民主评议均分");
HSSFCell e7 = fiveRow.createCell(6);
e7.setCellValue("年度民测积分");
HSSFCell e8 = fiveRow.createCell(7);
e8.setCellValue("上半年得分");
HSSFCell e9 = fiveRow.createCell(8);
e9.setCellValue("下半年得分");
HSSFCell e10 = fiveRow.createCell(9);
e10.setCellValue("年度累计创优得分");
HSSFCell e11 = fiveRow.createCell(10);
e11.setCellValue("上半年扣分");
HSSFCell e12 = fiveRow.createCell(11);
e12.setCellValue("下半年扣分");
HSSFCell e13 = fiveRow.createCell(12);
e13.setCellValue("年度累计扣分");
HSSFCellStyle headerStyle = (HSSFCellStyle) workbook.createCellStyle();
headerStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
headerStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
HSSFFont headerFont = (HSSFFont) workbook.createFont();
headerFont.setFontName("黑体");
headerFont.setFontHeightInPoints((short) 20);
headerStyle.setFont(headerFont);
a0.setCellStyle(headerStyle);
HSSFCellStyle headerStyle1 = (HSSFCellStyle) workbook.createCellStyle();
headerStyle1.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
headerStyle1.setAlignment(HSSFCellStyle.ALIGN_CENTER);
HSSFFont headerFont1 = (HSSFFont) workbook.createFont();
headerFont1.setFontName("楷体");
headerFont1.setFontHeightInPoints((short) 20);
headerStyle1.setFont(headerFont1);
b0.setCellStyle(headerStyle1);
HSSFCellStyle headerStyle2 = (HSSFCellStyle) workbook.createCellStyle();
headerStyle2.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
headerStyle2.setAlignment(HSSFCellStyle.ALIGN_CENTER);
HSSFFont headerFont2 = (HSSFFont) workbook.createFont();
headerFont2.setFontName("宋体");
headerFont2.setFontHeightInPoints((short) 11);
headerStyle2.setFont(headerFont2);
HSSFCellStyle headerStyle3 = (HSSFCellStyle) workbook.createCellStyle();
headerStyle3.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
headerStyle3.setAlignment(HSSFCellStyle.ALIGN_LEFT);
HSSFFont headerFont3 = (HSSFFont) workbook.createFont();
headerFont3.setFontName("黑体");
headerFont3.setFontHeightInPoints((short) 11);
headerStyle3.setFont(headerFont3);
c0.setCellStyle(headerStyle2);
c1.setCellStyle(headerStyle2);
c2.setCellStyle(headerStyle2);
c3.setCellStyle(headerStyle2);
d0.setCellStyle(headerStyle2);
d1.setCellStyle(headerStyle2);
d2.setCellStyle(headerStyle2);
d3.setCellStyle(headerStyle2);
e3.setCellStyle(headerStyle2);
e4.setCellStyle(headerStyle2);
e5.setCellStyle(headerStyle2);
e6.setCellStyle(headerStyle2);
e7.setCellStyle(headerStyle2);
e8.setCellStyle(headerStyle2);
e9.setCellStyle(headerStyle2);
e10.setCellStyle(headerStyle2);
e11.setCellStyle(headerStyle2);
e12.setCellStyle(headerStyle2);
e13.setCellStyle(headerStyle2);
sheet.addMergedRegion(new CellRangeAddress(0, 0, (short) 0, (short) 13));
sheet.addMergedRegion(new CellRangeAddress(1, 1, (short) 0, (short) 13));
sheet.addMergedRegion(new CellRangeAddress(2, 4, (short) 0, (short) 0));
sheet.addMergedRegion(new CellRangeAddress(2, 4, (short) 1, (short) 1));
sheet.addMergedRegion(new CellRangeAddress(2, 2, (short) 2, (short) 12));
sheet.addMergedRegion(new CellRangeAddress(3, 3, (short) 2, (short) 4));
sheet.addMergedRegion(new CellRangeAddress(3, 3, (short) 5, (short) 6));
sheet.addMergedRegion(new CellRangeAddress(3, 3, (short) 7, (short) 9));
sheet.addMergedRegion(new CellRangeAddress(3, 3, (short) 10, (short) 12));
sheet.addMergedRegion(new CellRangeAddress(2, 4, (short) 13, (short) 13));
for (int i = 0; i < list.size(); i++) {
HSSFRow row = sheet.createRow(i + 5);
HSSFCell oneCell = row.createCell(0);
oneCell.setCellValue(i + 1);
oneCell.setCellStyle(headerStyle2);
HSSFCell twoCell = row.createCell(1);
twoCell.setCellValue(list.get(i).getName());
twoCell.setCellStyle(headerStyle2);
HSSFCell threeCell = row.createCell(2);
threeCell.setCellValue(list.get(i).getJcfs());
threeCell.setCellStyle(headerStyle2);
HSSFCell fourCell = row.createCell(3);
fourCell.setCellValue(list.get(i).getJcfx());
fourCell.setCellStyle(headerStyle2);
HSSFCell fiveCell = row.createCell(4);
fiveCell.setCellValue(list.get(i).getNdjcf());
fiveCell.setCellStyle(headerStyle2);
HSSFCell sixCell = row.createCell(5);
sixCell.setCellValue(list.get(i).getMzcejf());
sixCell.setCellStyle(headerStyle2);
HSSFCell sevenCell = row.createCell(6);
sevenCell.setCellValue(list.get(i).getMzcef());
sevenCell.setCellStyle(headerStyle2);
HSSFCell eightCell = row.createCell(7);
eightCell.setCellValue(list.get(i).getCyjfs());
eightCell.setCellStyle(headerStyle2);
HSSFCell nineCell = row.createCell(8);
nineCell.setCellValue(list.get(i).getCyjfx());
nineCell.setCellStyle(headerStyle2);
HSSFCell tenCell = row.createCell(9);
tenCell.setCellValue(list.get(i).getCyjf());
tenCell.setCellStyle(headerStyle2);
HSSFCell elevenCell = row.createCell(10);
elevenCell.setCellValue(list.get(i).getNdkfs());
elevenCell.setCellStyle(headerStyle2);
HSSFCell twelveCell = row.createCell(11);
twelveCell.setCellValue(list.get(i).getNdkfx());
twelveCell.setCellStyle(headerStyle2);
HSSFCell thirteenCell = row.createCell(12);
thirteenCell.setCellValue(list.get(i).getNdkfx());
thirteenCell.setCellStyle(headerStyle2);
HSSFCell fourteenCell = row.createCell(13);
fourteenCell.setCellValue(list.get(i).getNdzjf());
fourteenCell.setCellStyle(headerStyle2);
}
HSSFRow listSizeRow = sheet.createRow(list.size() + 5);
HSSFCell listSizecell = listSizeRow.createCell(0);
listSizecell.setCellValue("支委员会委员: (签名)");
sheet.addMergedRegion(new CellRangeAddress(list.size() + 5, list.size() + 6, (short) 0, (short) 13));
listSizecell.setCellStyle(headerStyle3);
response.reset();
response.setContentType("application/octet-stream; charset=utf-8");
if (StringUtils.isEmpty(years)) {
response.setHeader("Content-Disposition", "attachment; filename=" + EncodeUtils.encodeUrl("太极实业综合党支部“微积分”制考核党员" + String.valueOf(cal.get(Calendar.YEAR)) + "年度积分管理表.xls"));
} else {
response.setHeader("Content-Disposition", "attachment; filename=" + EncodeUtils.encodeUrl("太极实业综合党支部“微积分”制考核党员" + years + "年度积分管理表.xls"));
}
OutputStream out = response.getOutputStream();
workbook.write(out);
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}