Java数据导出为Excel表格

<span style="white-space:pre">		</span>HSSFWorkbook wb = new HSSFWorkbook();
		HSSFCell cell;
		HSSFSheet sheet = wb.createSheet("结果导出");

		// /设置行高 row0.setHeight((short)780);
		// /设置列宽 sheet.setColumnWidth((short)1,(short)5900);

		HSSFCellStyle cellStyle = setCellStyle(wb);
		HSSFFont font = setFontStyle(wb, (short) 15, " 宋体 "); // 设置字体
		font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
		cellStyle.setFont(font);
		cellStyle.setVerticalAlignment((short) 1); // 单元格垂直 0 居上 1 居中 2 居下 3 正当
		cellStyle.setWrapText(true);

		HSSFCellStyle cellStyle1 = setCellStyle(wb);
		HSSFFont font1 = setFontStyle(wb, (short) 12, " 宋体 ");
		font1.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
		cellStyle1.setFont(font1);
		cellStyle1.setVerticalAlignment((short) 1);
		cellStyle1.setWrapText(true);

		HSSFCellStyle cellStyle2 = setCellStyle(wb);
		HSSFFont font2 = setFontStyle(wb, (short) 12, " 宋体 ");
		cellStyle2.setFont(font2);
		cellStyle2.setVerticalAlignment((short) 1);
		cellStyle2.setWrapText(true);

		HSSFCellStyle cellStyle3 = setCellStyle(wb);
		HSSFFont font3 = setFontStyle(wb, (short) 10, " 宋体 ");
		cellStyle3.setFont(font3);
		cellStyle3.setVerticalAlignment((short) 1);
		cellStyle3.setWrapText(true);

		HSSFCellStyle cellStyle4 = setCellStyle(wb);
		HSSFFont font4 = setFontStyle(wb, (short) 10, " 宋体 ");
		cellStyle4.setFont(font4);
		cellStyle4.setVerticalAlignment((short) 1);
		cellStyle4.setWrapText(true); // 设置单元格自动换行
		cellStyle4.setAlignment((short) 2); // 单元格水平 0普通 1 左对齐2 居中3 右对齐4 填充5 正当6
											// 居中选择
<span>		</span>DealString ds = new DealString();

		HSSFCellStyle cellStyle5 = setCellStyle(wb);
		HSSFFont font5 = setFontStyle(wb, (short) 10, " 宋体 ");
		font5.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
		cellStyle5.setFont(font5);
		cellStyle5.setVerticalAlignment((short) 1);
		cellStyle5.setWrapText(true); // 设置单元格自动换行
		cellStyle5.setAlignment((short) 2); // 单元格水平 0普通 1 左对齐2 居中3 右对齐4 填充5 正当6
											// 居中选择

		HSSFRow row1 = sheet.createRow((short) 0);
		HSSFRow row;

		cell = row1.createCell((short) 0);
		cell.setCellValue("课题名");
		cell.setCellStyle(cellStyle5);
		sheet.setColumnWidth((short) 0, (short) 3900);

		cell = row1.createCell((short) 1);
		cell.setCellValue("课题性质名称");
		cell.setCellStyle(cellStyle5);
		sheet.setColumnWidth((short) 1, (short) 3900);
                 //shuju chaxun return rslist
                 for (int i = 0; i < rslist.size(); i++) {
			HashMap xxmap = (HashMap) rslist.get(i);
			row = sheet.createRow((short) (1 + i));

			cell = row.createCell((short) 0);
			cell.setCellValue(ds.toString(xxmap.get("ktmc")));
			cell.setCellStyle(cellStyle4);

			cell = row.createCell((short) 1);
			cell.setCellValue(ds.toString(xxmap.get("ktxzmc")));
			cell.setCellStyle(cellStyle4);
<span>		</span>}

		response.reset();
		response.setContentType("application/vnd.ms-excel");
		response.addHeader("Content-Disposition", "attachment; filename="
				+ new String("学生基本信息导出.xls".getBytes(), "ISO8859-1"));
		wb.write(response.getOutputStream());
		response.getOutputStream().close();
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值