public ActionForward export(ActionMapping mapping, ActionForm form,
HttpServletRequest req, HttpServletResponse resp)throws Exception {
String[] head={"列名","","",""};//表头
Form frm = (Form)form;
List data=new ArrayList();
data = dao.getExcelList(frm);//导出数据
HSSFWorkbook wb=new HSSFWorkbook();
HSSFSheet sheet1=wb.createSheet("sheet1");
HSSFRow row=sheet1.createRow((short)(0));
for(int i=0;i<head.length;i++){
HSSFCell cell=row.createCell((short)(i));
cell.setEncoding(HSSFWorkbook.ENCODING_UTF_16);
cell.setCellValue(head[i]);
}
for(int k=0;k<data.size();k++){
String[] str_array=(String[])data.get(k);
row=sheet1.createRow((short)(k+1));
for(int h=0;h<str_array.length;h++){
HSSFCell cell_data=row.createCell((short)h);
cell_data.setEncoding(HSSFWorkbook.ENCODING_UTF_16);
cell_data.setCellValue(str_array[h]);
}
}
resp.setContentType ( "application/ms-excel" );
resp.setHeader ( "Content-Disposition" ,
"attachment;filename="+new String("表名".getBytes("GBK"),"iso-8859-1")+".xls") ;
wb.write(resp.getOutputStream());
return null;
}