xls文档的导出
/**
* 导出
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws IOException
* @throws SQLException
* @throws Exception
*/
public ActionForward exportSample(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws IOException, SQLException{
CommonActionForm aForm = (CommonActionForm)form;
Dto oDto = aForm.getParamAsDto(request);
Integer count=(Integer) appReader.queryForObject("sample.queryIntanceCount", oDto);
Dto SampleinfofirstRowdt=(Dto)appReader.queryForList("sample.querySampleinfoFirstRow",oDto).get(0);//标题那一行
List<Dto> SampleinfoOtherRow= appReader.queryForList("sample.querySampleinfoOtherRow",oDto); //其他行
WritableSheet sheet = null;
try {
WritableWorkbook workbook = Workbook.createWorkbook(response.getOutputStream());
if(workbook != null){
sheet = workbook.createSheet("sheet1", 0);
sheet.addCell(new Label(0,0,"病历号"));
sheet.addCell(new Label(1,0,"标本类型"));
sheet.addCell(new Label(2,0,"实验室ID"));
sheet.addCell(new Label(3,0,"冰箱ID"));
sheet.addCell(new Label(4,0,"冰箱层数"));
sheet.addCell(new Label(5,0,"冻存架数"));
sheet.addCell(new Label(6,0,"行"));
sheet.addCell(new Label(7,0,"高"));
sheet.addCell(new Label(8,0,"深"));
sheet.addCell(new Label(9,0,"冻存盒编号"));
sheet.addCell(new Label(10,0,"冻存盒位置"));
for(int i=1;i<=300;i++){
String s_n="s"+i;
String firstsource=SampleinfofirstRowdt.getAsString(s_n);
if(G4Utils.isEmpty(firstsource)){
break;
}
sheet.addCell(new Label(10+i,0,firstsource));
}
}
if(SampleinfoOtherRow.size()>0){
for(int i = 0; i < SampleinfoOtherRow.size(); i++){
int row = i+1;
Dto dt = SampleinfoOtherRow.get(i);//后面的字段
String intance_patient=dt.getAsString("sample_patient");
oDto.put("intance_patient", intance_patient);
Dto d=(Dto) appReader.queryForList("sample.queryIntanceList", oDto).get(0);//前面的字段
sheet.addCell(new Label(0,row,d.getAsString("intance_patient")));
String sample_type=WebUtils.getCodeDesc("SAMPLE_TYPE",d.getAsString("intance_type"));
sheet.addCell(new Label(1,row,sample_type));
sheet.addCell(new Label(2,row,d.getAsString("lab_id")));
sheet.addCell(new Label(3,row,d.getAsString("ice_id")));
sheet.addCell(new Label(4,row,d.getAsString("ice_floorno")));
sheet.addCell(new Label(5,row,d.getAsString("ice_framesno")));
sheet.addCell(new Label(6,row,d.getAsString("ice_row")));
sheet.addCell(new Label(7,row,d.getAsString("ice_high")));
sheet.addCell(new Label(8,row,d.getAsString("ice_deep")));
sheet.addCell(new Label(9,row,d.getAsString("box_id")));
String box_x=d.getAsString("box_x");
String box_y=d.getAsString("box_y");
sheet.addCell(new Label(10,row,box_x+box_y));
for(int j=1;j<=300;j++){
String s_n="s"+j;
String firstsource=dt.getAsString(s_n);
if(G4Utils.isEmpty(firstsource)){
break;
}
sheet.addCell(new Label(10+j,row,firstsource));
}
}
}
response.reset();
response.setHeader("Content-disposition","attachment; filename=" + new String("标本.xls".getBytes("GBK"),"iso-8859-1"));
response.setContentType("application/vnd.ms-excel;charset=GBK");
workbook.write();
workbook.close();
} catch (Exception e) {
// TODO: handle exception
}
return mapping.findForward(null);
}
jsp页面
//导出
function exportSample(){
var url = "/busi/sampleAction.ered?reqCode=exportSample&sample_id="+sample_id;
window.location = url;
}

浙公网安备 33010602011771号