JavaエクスポートExcel
12930 ワード
List leadInfoList = leadInfoMapper.downloadExcel(requestContext, leadInfo, page, pagesize);
String result = "Excel !";
//
String[] Title = new String[] { " ", " ", " ", " ", " ", " "};
// EXCEL
try {
// , ______________________begin
OutputStream opStream = response.getOutputStream();//
response.reset();//
//
response.setHeader("Content-disposition",
"attachment; filename=" + new String("event.xls".getBytes("GB2312"), "ISO8859-1"));
response.setContentType("application/msexcel");//
// , ______________________end
/************* *************/
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
/** ********** ************ */
WritableWorkbook workbook = Workbook.createWorkbook(opStream);
/** ********** ************ */
WritableSheet sheet = workbook.createSheet("Sheet1", 0);
/** ********** ( )、 ***************** */
jxl.SheetSettings sheetset = sheet.getSettings();
sheetset.setOrientation(PageOrientation.LANDSCAPE);
sheetset.setProtected(false);
/** ************ ************** */
WritableFont NormalFont = new WritableFont(WritableFont.ARIAL, 10);
WritableFont BoldFont = new WritableFont(WritableFont.ARIAL, 10, WritableFont.BOLD);
DisplayFormat dFormat = NumberFormats.TEXT;
/** ************ , ************ */
//
WritableCellFormat wcf_center = new WritableCellFormat(BoldFont, dFormat);
wcf_center.setBorder(Border.ALL, BorderLineStyle.THIN); //
wcf_center.setVerticalAlignment(VerticalAlignment.CENTRE); //
wcf_center.setAlignment(Alignment.CENTRE); //
wcf_center.setWrap(false); //
//
WritableCellFormat wcf_left = new WritableCellFormat(NormalFont, dFormat);
wcf_left.setBorder(Border.NONE, BorderLineStyle.THIN); //
wcf_left.setVerticalAlignment(VerticalAlignment.CENTRE); //
wcf_left.setAlignment(Alignment.CENTRE); //
wcf_left.setWrap(false); //
/** *************** EXCEL , ********************* */
// sheet.mergeCells(0, 0, colWidth, 0);
// sheet.addCell(new Label(0, 0, "XX ", wcf_center));
/** *************** EXCEL ********************* */
for (int i = 0; i < Title.length; i++) {
sheet.addCell(new Label(i, 0, Title[i], wcf_center));
}
/** *************** EXCEL ********************* */
int i = 1;
for (LeadInfo leadInfo1 : leadInfoList) {
sheet.addCell(new Label(0, i, "", wcf_left));
sheet.addCell(new Label(1, i, "", wcf_left));
sheet.addCell(new Label(2, i, "", wcf_left));
sheet.addCell(new Label(3, i, "", wcf_left));
sheet.addCell(new Label(4, i, "", wcf_left));
sheet.addCell(new Label(5, i, "", wcf_left));
i++;
}
/** ********** EXCEL ******** */
workbook.write();
/** ********* ************* */
workbook.close();
} catch (Exception e) {
result = " :excel , :" + e.toString();
System.out.println(e.toString());
e.printStackTrace();
}
return result;