JavaデータをExcelテーブルにエクスポート
3296 ワード
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
//
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);
}
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();