Java操作Jxl实现导出数据生成Excel表格数据文件
程序员文章站
2022-07-28 16:00:37
实现:前台用的框架是Easyui+Bootstrap结合使用,需要引入相应的Js、Css文件。页面:Jsp、拦截请求:Servlet、逻辑处理:ClassBean、数据库:SQLserver。 注意:Bean中操作SQL语句进行处理是公司内部方法,可替换为其它方法自行扩展!主要看代码逻辑业务处理! ......
实现:前台用的框架是easyui+bootstrap结合使用,需要引入相应的js、css文件。页面:jsp、拦截请求:servlet、逻辑处理:classbean、数据库:sqlserver。
注意:bean中操作sql语句进行处理是公司内部方法,可替换为其它方法自行扩展!主要看代码逻辑业务处理!
使用sqlserver数据库进行多表连接查询得出需要展出的数据
则前台数据展示使用的是easyui中的datagrid数据列表进行展示。
随机点击一行数据,点击详情个人信息弹窗打开,数据以及被填充到弹窗中!
拉到底部可见导出按钮,点击导出发送请求:传入个人就诊编号及卡号进行sql查询个人数据实现导出
此时此刻java操作jxl生成excel文件成功直接,让我们打开文件查看数据是否和我们后台设置的预期效果一致!
表格数据和预期效果一致代码如下:
bean代码:
import java.io.file; import java.io.filenotfoundexception; import java.io.fileoutputstream; import java.io.ioexception; import java.io.outputstream; import jxl.cellview; import jxl.workbook; import jxl.format.border; import jxl.format.borderlinestyle; import jxl.format.colour; import jxl.write.label; import jxl.write.writablecellformat; import jxl.write.writablefont; import jxl.write.writablesheet; import jxl.write.writableworkbook; import jxl.write.writeexception; public class importbean { private httpservletrequest request;//客户端请求对象 private dbsource db; //操作sql语句对象 private string msg; //提示信息 //构造函数 public importbean(httpservletrequest request) { this.request = request; this.db = new dbsource(request); // 数据库对象 } //主诉与症状下拉框 public vector loadzszzcombo() throws sqlexception{ vector vec = null; string sql =" select '' as combovalue,'请选择' as comboname, '' as combotext "+ "union all " + "select [编号],[主诉与症状],[查体] from [v_医务管理_主诉症状信息表]"; sql+=" order by combovalue "; vec = db.getconttexjonsarr(sql, 0, 0); return vec; } //页面初始化读取就诊信息 public vector queryjzxx(int pagenum, int pagesize,string jzbh,string kh) throws sqlexception{ string sql = ""; // 查询用sql语句 vector vec = null; // 结果集 sql="select 就诊编号,卡号,姓名,班级或部门,人员类型,就诊医生,convert(nvarchar(19),就诊时间,21) as 就诊时间,主诉与症状,查体,是否隔离,诊断结果,诊疗意见,病历类型,isnull(转院原因,'') as 转院原因,isnull(转诊医院,'') as 转诊医院,isnull(转诊医生,'') as 转诊医生,isnull(convert(nvarchar(19),转院时间,21),'') as 转院时间 from ( select l.就诊编号,a.[卡号],a.[姓名],b.班级名称 as 班级或部门,'1' as 人员类型,j.就诊医生,j.就诊时间 as 就诊时间,l.主诉与症状,l.查体,l.是否隔离,l.诊断结果,l.诊疗意见,l.病历类型,z.转院原因,z.转诊医院,z.转诊医生,z.转院时间" + " from [v_基础信息_学生信息表] a "+ " left join [v_医务管理_就诊信息] j on j.卡号=a.卡号 left join [v_医务管理_病历信息] l on l.就诊编号=j.编号 " + " left join [v_医务管理_转院信息] z on z.就诊编号=j.编号 left join dbo.v_基础信息_班级信息表 b on a.[行政班代码]=b.班级代码 "+ " union all select l.就诊编号,a.[卡号],a.[姓名],c.cname as 班级或部门,'2' as 人员类型,j.就诊医生,convert(nvarchar(19),j.就诊时间,21) as 就诊时间,l.主诉与症状,l.查体,l.是否隔离,l.诊断结果,l.诊疗意见,l.病历类型,isnull(z.转院原因,'') as 转院原因,isnull(z.转诊医院,'') as 转诊医院,isnull(z.转诊医生,'') as 转诊医生,isnull(convert(nvarchar(19),z.转院时间,21),'')as 转院时间 " + " from [v_基础信息_教职工信息表] a "+ " left join [v_医务管理_就诊信息] j on j.卡号=a.卡号 left join [v_医务管理_病历信息] l on l.就诊编号=j.编号 "+ " left join [v_医务管理_转院信息] z on z.就诊编号=j.编号 left join [sysuserdept] b on a.卡号=b.[usercode] "+ " left join [sysdepartment] c on b.[deptcode]=c.[deptcode] ) x where 1=1 and x.就诊医生!='null' "; if(!"".equalsignorecase(jzbh)){ sql+=" and x.就诊编号='"+ mytools.fixsql(jzbh) +"' "; } if(!"".equalsignorecase(kh)){ sql+=" and x.卡号='"+ mytools.fixsql(kh) +"' "; } sql+=" order by x.人员类型,x.[卡号] desc"; vec = db.getconttexjonsarr(sql, pagenum, pagesize); return vec; } //导出excel表格 public string outputgrxx(string jzbh,string kh)throws sqlexception { vector vec = null; vector vec2 = null; string sql=""; string sql2=""; string savepath=""; sql="select 卡号,姓名,班级或部门,人员类型,就诊医生,convert(nvarchar(19),就诊时间,21) as 就诊时间,主诉与症状,查体,是否隔离,诊断结果,诊疗意见,病历类型,是否转院,isnull(转院原因,'') as 转院原因,isnull(转诊医院,'') as 转诊医院,isnull(转诊医生,'') as 转诊医生,isnull(convert(nvarchar(19),转院时间,21),'') as 转院时间 from ( select l.就诊编号,a.[卡号],a.[姓名],b.班级名称 as 班级或部门,'1' as 人员类型,j.就诊医生,j.就诊时间 as 就诊时间,l.主诉与症状,l.查体,l.是否隔离,l.诊断结果,l.诊疗意见,l.病历类型,是否转院='',z.转院原因,z.转诊医院,z.转诊医生,z.转院时间" + " from [v_基础信息_学生信息表] a "+ " left join [v_医务管理_就诊信息] j on j.卡号=a.卡号 left join [v_医务管理_病历信息] l on l.就诊编号=j.编号 " + " left join [v_医务管理_转院信息] z on z.就诊编号=j.编号 left join dbo.v_基础信息_班级信息表 b on a.[行政班代码]=b.班级代码 "+ " union all select l.就诊编号,a.[卡号],a.[姓名],c.cname as 班级或部门,'2' as 人员类型,j.就诊医生,convert(nvarchar(19),j.就诊时间,21) as 就诊时间,l.主诉与症状,l.查体,l.是否隔离,l.诊断结果,l.诊疗意见,l.病历类型,是否转院='',isnull(z.转院原因,'') as 转院原因,isnull(z.转诊医院,'') as 转诊医院,isnull(z.转诊医生,'') as 转诊医生,isnull(convert(nvarchar(19),z.转院时间,21),'')as 转院时间 " + " from [v_基础信息_教职工信息表] a "+ " left join [v_医务管理_就诊信息] j on j.卡号=a.卡号 left join [v_医务管理_病历信息] l on l.就诊编号=j.编号 "+ " left join [v_医务管理_转院信息] z on z.就诊编号=j.编号 left join [sysuserdept] b on a.卡号=b.[usercode] "+ " left join [sysdepartment] c on b.[deptcode]=c.[deptcode] ) x where 1=1 and x.就诊医生!='null' and x.就诊编号='"+ mytools.fixsql(jzbh) +"' and x.卡号='"+ mytools.fixsql(kh) +"' "; vec=db.getcontextvector(sql); //查询主诉与症状下拉框 sql2="select [编号],[主诉与症状],[查体] from [v_医务管理_主诉症状信息表]"; vec2=db.getcontextvector(sql2); //生成excel表 if (vec != null && vec.size() > 0) { calendar c = calendar.getinstance();// 可以对每个时间域单独修改 savepath = mytools.getprop(request, "base.exportexcelpath");//导出excel文件服务器保存路径:f\:/upload/xzlms/exportexcel/ //创建文件夹 file file = new file(savepath); if (!file.exists()) { file.mkdirs(); } savepath +=vec.get(1).tostring() +"就诊记录详情"+ ".xls"; system.out.println(savepath); try { outputstream os = new fileoutputstream(savepath); writableworkbook wbook = workbook.createworkbook(os);// 建立excel文件 writablesheet wsheet1 = wbook.createsheet(vec.get(1).tostring(), 0);// 对第一张sheete,生成的工作表名称 writablefont fontstyle; writablecellformat contentstyle; label content; //生成标题 string[] title1=new string[]{"卡号","姓名","班级或部门","人员类型","就诊医生","就诊时间","主诉与症状","查体","是否隔离","诊断结果","诊疗意见","病历类型","是否转院","转院原因","转诊医院","转诊医生","转院时间"}; int counum1=0;//excel表中行数 string cellcontent1 = ""; //当前单元格的内容 for(int i=0;i<title1.length;i++) { wsheet1.setcolumnview(i, 25);//设置每列列宽 } //第1行生成标题设置行列字体大小 fontstyle = new writablefont(writablefont.createfont("宋体"), 20, writablefont.bold,false, jxl.format.underlinestyle.no_underline,jxl.format.colour.black); contentstyle = new writablecellformat(fontstyle); contentstyle.setshrinktofit(true); contentstyle.setwrap(true); contentstyle.setalignment(jxl.format.alignment.centre);//水平居中 contentstyle.setverticalalignment(jxl.format.verticalalignment.centre);//垂直居中 wsheet1.mergecells(0, counum1, 16, counum1); //合并单元格mergecells(a,b,c,d) a 单元格的列号,b 单元格的行号,c 从单元格[a,b]起,向左合并到c列,d 从单元格[a,b]起,向下合并到d行 cellcontent1 = "个人就诊信息详情表"; content = new label(0, counum1, cellcontent1, contentstyle); //单元格内容 wsheet1.addcell(content); wsheet1.setrowview(counum1, 600); //设置行高 //第2行生成对应数据标题名称。 counum1++; for(int colnum=0; colnum<17; colnum++){ fontstyle = new writablefont(writablefont.createfont("宋体"), 12, writablefont.no_bold,false, jxl.format.underlinestyle.no_underline,jxl.format.colour.black); contentstyle = new writablecellformat(fontstyle); contentstyle.setshrinktofit(true); contentstyle.setalignment(jxl.format.alignment.centre);//水平居中 contentstyle.setverticalalignment(jxl.format.verticalalignment.centre);//垂直居中 //设置边框; contentstyle.setborder(jxl.format.border.top, borderlinestyle.thin); contentstyle.setborder(jxl.format.border.left, borderlinestyle.thin); contentstyle.setborder(jxl.format.border.right, borderlinestyle.thin); contentstyle.setborder(jxl.format.border.bottom, borderlinestyle.thin); //创建单元格 ,一行一个格子的增加 cellcontent1=title1[colnum]; content = new label(colnum, counum1, cellcontent1, contentstyle); //添加到行中; wsheet1.addcell(content); } wsheet1.setrowview(counum1, 1000); //设置行高 //第3行生成内容数据 counum1++; for(int i=0;i<vec.size();i=i+18){//控制行数 for(int colnum=0; colnum<17; colnum++){//控制列数 fontstyle = new writablefont(writablefont.createfont("宋体"), 12, writablefont.no_bold,false, jxl.format.underlinestyle.no_underline,jxl.format.colour.black); contentstyle = new writablecellformat(fontstyle); contentstyle.setwrap(true); contentstyle.setshrinktofit(true); contentstyle.setalignment(jxl.format.alignment.centre);//水平居中 contentstyle.setverticalalignment(jxl.format.verticalalignment.centre);//垂直居中 //边框 contentstyle.setborder(jxl.format.border.top, borderlinestyle.thin); contentstyle.setborder(jxl.format.border.left, borderlinestyle.thin); contentstyle.setborder(jxl.format.border.right, borderlinestyle.thin); contentstyle.setborder(jxl.format.border.bottom, borderlinestyle.thin); //对某一列进行判断进行单独处理 if(colnum==3) { if(vec.get(i+colnum).tostring().equalsignorecase("1")) { cellcontent1="学生"; }else { cellcontent1="教师"; } content = new label(colnum, counum1, cellcontent1, contentstyle);//创建单元格 第?列单元格y坐标 ,第?行x坐标,内容,样式 wsheet1.addcell(content); //添加到行中; }else if(colnum==6) {//症状 for(int j=0;j<vec2.size();j=j+3) { if(vec2.get(j+0).tostring().equalsignorecase(vec.get(i+colnum).tostring())) { cellcontent1=vec2.get(j+1).tostring(); } } content = new label(colnum, counum1, cellcontent1, contentstyle);//创建单元格 第?列单元格y坐标 ,第?行x坐标,内容,样式 wsheet1.addcell(content); //添加到行中; }else if(colnum==8) {//隔离 if(vec.get(i+colnum).tostring().equalsignorecase("0")) { cellcontent1="否"; }else { cellcontent1="是"; } content = new label(colnum, counum1, cellcontent1, contentstyle);//创建单元格 第?列单元格y坐标 ,第?行x坐标,内容,样式 wsheet1.addcell(content); //添加到行中; }else if(colnum==11) {//病历类型 if(vec.get(i+colnum).tostring().equalsignorecase("1")) { cellcontent1="初诊"; }else { cellcontent1="复诊"; } content = new label(colnum, counum1, cellcontent1, contentstyle);//创建单元格 第?列单元格y坐标 ,第?行x坐标,内容,样式 wsheet1.addcell(content); //添加到行中; }else if(colnum==12) {//是否转院 if(vec.get(i+(colnum+1)).tostring().equalsignorecase("")) { cellcontent1="否"; }else { cellcontent1="是"; } content = new label(colnum, counum1, cellcontent1, contentstyle);//创建单元格 第?列单元格y坐标 ,第?行x坐标,内容,样式 wsheet1.addcell(content); //添加到行中; }else{ //正常拼接值 cellcontent1=vec.get(i+colnum).tostring(); content = new label(colnum, counum1, cellcontent1, contentstyle);//创建单元格 第?列单元格y坐标 ,第?行x坐标,内容,样式 wsheet1.addcell(content); //添加到行中; } } wsheet1.setrowview(counum1, 1500); //设置行高 counum1++; } // 写入数据 wbook.write(); // 关闭文件 wbook.close(); os.close(); this.setmsg("文件生成成功"); } catch (filenotfoundexception e) { this.setmsg("导出前请先关闭相关excel"); } catch (writeexception e) { this.setmsg("文件生成失败"); } catch (ioexception e) { this.setmsg("文件生成失败"); } } else { this.setmsg("没有符合条件的成绩信息"); } return savepath; } //get&set public string getmsg() { return msg; } public void setmsg(string msg) { msg = msg; } }
servlet代码:
public class importbean_servlet extends httpservlet { protected void doget(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { dopost(request, response); } protected void dopost(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { //设置字符编码为utf-8 request.setcharacterencoding("utf-8"); response.setcontenttype("text/html;charset=utf-8"); string active = mytools.strfiltr(request.getparameter("active"));// 拿取前台的active值 int pagenum = mytools.parseint(request.getparameter("page")); //获得页面page参数 分页 int pagesize = mytools.parseint(request.getparameter("rows")); //获得页面rows参数 分页 tracelog.trace("active...:"+active); vector jsonv = null;//返回结果集 jsonarray jal = null;//返回json对象 importbean bean = new importbean(request); //对象 //查询主诉与症状 if("loadzszzcombo".equalsignorecase(active)){ try { jsonv = bean.loadzszzcombo(); jal = (jsonarray) jsonv.get(2); response.getwriter().write(jal.tostring()); } catch (exception e) { e.printstacktrace(); } } //查询就诊信息 if("queryjzxx".equalsignorecase(active)){ try { string jzbh=urldecoder.decode(mytools.strfiltr(request.getparameter("jzbh")), "utf-8");//就诊编号 string kh=urldecoder.decode(mytools.strfiltr(request.getparameter("kh")), "utf-8");//卡号 jsonv = bean.queryjzxx(pagenum,pagesize,jzbh,kh); if (jsonv != null && jsonv.size() > 0) { //最终处理:传回ajax 结果集 jal = (jsonarray)jsonv.get(2); response.getwriter().write("{\"total\":" + mytools.strfiltr(jsonv.get(0)) + ",\"rows\":" + jal.tostring() + "}");//生成datagrid所需数据类型 } } catch (sqlexception e) { // todo auto-generated catch block e.printstacktrace(); jal = jsonutil.addjsonparams(jal, "msg", "查询错误!"+ bean.getmsg() ); response.getwriter().write(jal.tostring()); } } //导出个人信息详情exls表格 if("outputgrxx".equalsignorecase(active)){ string jzbh=urldecoder.decode(mytools.strfiltr(request.getparameter("jzbh")), "utf-8");//就诊编号 string kh=urldecoder.decode(mytools.strfiltr(request.getparameter("kh")), "utf-8");//卡号 try { string filepath=bean.outputgrxx(jzbh,kh); //调用bean方法入参,返回生成文件路径 jal = jsonutil.addjsonparams(jal, "msg",bean.getmsg()); //生成json格式数据,返回状态值 jal = jsonutil.addjsonparams(jal, "filepath", filepath);//生成json格式数据,返回路径 response.getwriter().write(jal.tostring()); } catch (sqlexception e) { // todo auto-generated catch block e.printstacktrace(); } } } }
jsp:代码:
<body> <%-- 遮罩层 --%> <div id="divpagemask" class="maskstyle"> <div id="maskfont">文件生成中,请稍后...</div> </div> <div class="bg-box indexbox" > <div class="box"> <div class="col-lg-10 col-md-10 col-sm-12 col-xs-12 content" style="width:100%;"> <div class="content-border"> <ol class="breadcrumb"> <li>就诊信息</li> <li class="active"><b>查询条件</b></li> </ol> <!-- 列表区 --> <div id="tablediv" class="list-table table-responsive" style="height:400px;"> <table id="jzxxlist" width="100%"></table> </div> </div> </div> </div> </div> <!-- 个人详细详情dialog --> <div id="grxxinfodialog" style="overflow:auto;"> <div class="col-lg-10 col-md-10 col-sm-12 col-xs-12 content" style="width:100%;"> <div class="content-border"> <div id="querybox"> <form id="form3" name="form3" method="post" class="colorform"> <div class="row"> <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2" style="height:34px;"> <label class="formrowtitle">姓名</label> </div> <div class="col-lg-8 col-md-8 col-sm-4 col-xs-4" style="height:34px;"> <span id="brxm_dc" style="font-size:16px;"></span> </div> </div> <div class="row"> <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2" style="height:34px;"> <label class="formrowtitle">班级或部门</label> </div> <div class="col-lg-8 col-md-8 col-sm-4 col-xs-4" style="height:34px;"> <span id="bjbm_dc" style="font-size:16px;"></span> </div> </div> <div class="row"> <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2" style="height:34px;"> <label class="formrowtitle">人员类型</label> </div> <div class="col-lg-10 col-md-10 col-sm-10 col-xs-10" style="height:40px;"> <input class="form-control" id="srylx_dc" name="srylx" style="width:100%;" /> </div> </div> <div class="row"> <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2" style="height:34px;"> <label class="formrowtitle">就诊医生</label> </div> <div class="col-lg-10 col-md-10 col-sm-10 col-xs-10" style="height:40px;"> <input class="form-control" id="jzys_dc" name="jzys" style="width:100%;" /> </div> </div> <div class="row"> <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2" style="height:34px;"> <label class="formrowtitle">就诊时间</label> </div> <div class="col-lg-10 col-md-10 col-sm-10 col-xs-10" style="height:34px;"> <input class="form-control" id="jzsj_dc" name="jzsj" style="width:100%;" /> </div> </div> <div class="row"> <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2" style="height:34px;"> <label class="formrowtitle">主诉与症状</label> </div> <div class="col-lg-10 col-md-10 col-sm-10 col-xs-10" style="height:40px;"> <input class="form-control" id="zsyzz_dc" name="zsyzz" style="width:100%;" /> </div> </div> <div class="row"> <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2" style="height:34px;"> <label class="formrowtitle">查体</label> </div> <div class="col-lg-10 col-md-10 col-sm-10 col-xs-10" style="height:80px;"> <textarea class="form-control" id="ct_dc" name="ct" style="width:100%; height:80px;"></textarea> </div> </div> <div class="row"> <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2" style="height:34px;"> <label class="formrowtitle">是否隔离</label> </div> <div class="col-lg-10 col-md-10 col-sm-10 col-xs-10" style="height:40px;"> <input class="form-control" id="sfgl_dc" name="sfgl" style="width:100%;" /> </div> </div> <div class="row"> <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2" style="height:34px;"> <label class="formrowtitle">类型</label> </div> <div class="col-lg-10 col-md-10 col-sm-10 col-xs-10" style="height:40px;"> <input class="form-control" id="bllx_dc" name="bllx" style="width:100%;" /> </div> </div> <div class="row"> <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2" style="height:34px;"> <label class="formrowtitle">诊断结果</label> </div> <div class="col-lg-10 col-md-10 col-sm-10 col-xs-10" style="height:80px;"> <textarea class="form-control" id="zdjg_dc" name="zdjg" style="width:100%; height:80px;"></textarea> </div> </div> <div class="row"> <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2" style="height:34px;"> <label class="formrowtitle">诊疗意见</label> </div> <div class="col-lg-10 col-md-10 col-sm-10 col-xs-10" style="height:80px;"> <textarea class="form-control" id="zlyj_dc" name="zlyj" style="width:100%; height:80px;"></textarea> </div> </div> <div class="row"> <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2" style="height:34px;"> <label class="formrowtitle">是否转院</label> </div> <div class="col-lg-10 col-md-10 col-sm-10 col-xs-10" style="height:40px;"> <input class="form-control" id="sfzy_dc" name="sfzy" style="width:100%;" /> </div> </div> <div class="row"> <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2" style="height:34px;"> <label class="formrowtitle">转院原因</label> </div> <div class="col-lg-10 col-md-10 col-sm-10 col-xs-10" style="height:80px;"> <textarea class="form-control" id="zyyy_dc" name="zyyy" style="width:100%; height:80px;"></textarea> </div> </div> <div class="row"> <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2" style="height:34px;"> <label class="formrowtitle">转诊医院</label> </div> <div class="col-lg-10 col-md-10 col-sm-10 col-xs-10" style="height:40px;"> <input class="form-control" id="zzyy_dc" name="zzyy" style="width:100%;" maxlength="20"/> </div> </div> <div class="row"> <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2" style="height:34px;"> <label class="formrowtitle">转诊医生</label> </div> <div class="col-lg-10 col-md-10 col-sm-10 col-xs-10" style="height:40px;"> <input class="form-control" id="zzys_dc" name="zzys" style="width:100%;" maxlength="20"/> </div> </div> <div class="row"> <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2" style="height:34px;"> <label class="formrowtitle">转院时间</label> </div> <div class="col-lg-10 col-md-10 col-sm-10 col-xs-10" style="height:40px;"> <input class="form-control" id="zysj_dc" name="zysj" style="width:100%;" /> </div> </div> <div class="row"> <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 text-center"> <input type="button" id="outputgrxx" class="btn form-control btn-success dialogbuttom-btn" value="导出" onclick="dotoolbar(this.id);"/> </div> </div> <input type="hidden" id="active2" name="active"/> <input type="hidden" id="jzbh_dc" name="jzbh"/><!-- 人员姓名 --> <input type="hidden" id="kh_dc" name="kh"/><!-- 班级或部门 --> </form> </div> </div> </div> </div> <iframe id="exportiframe" src="" style="width:0; height:0;"></iframe> </body> <script type="text/javascript"> var usercode = '<%=usercode%>'; var sauth = '<%=sauth%>'; var curpagenumber = 1; var curpagesize = 20; var lodata=''; var jzbh='';//就诊编号 var kh='';//卡号 $(document).ready(function(){ $('#hidequeryarea').collapse('hide'); var tableheight=($(window).height()-308); //浏览器当前窗口可视区域高度 $('#tablediv').css("height", tableheight); if(screen.height>900){ dialogheight=160; }else{ dialogheight=10; } initdialog();//初始化对话框 loadfiand();//初始化主诉症状 loadgridjzxx();//页面初始化datagrid }); //加载主诉症状 function loadfiand(){ $.ajax({ type:"post", url:'<%=request.getcontextpath()%>/importbean_servlet?active=loadzszzcombo', datatype:"json", success: function(data){ lodata=''; lodata=data; } }); } /**加载 dialog控件**/ function initdialog(){ //个人详细信息弹窗 $('#grxxinfodialog').dialog({ width: 580,//宽度设置 height: 480,//高度设置 top: dialogheight, modal:true, closed: true, cache: false, draggable:false,//是否可移动dialog框设置 //打开事件 onopen:function(data){}, //读取事件 onload:function(data){}, //关闭事件 onclose:function(data){} }); } //页面初始化datagrid:查询就诊信息 function loadgridjzxx(){ $('#jzxxlist').datagrid({ url: '<%=request.getcontextpath()%>/importbean_servlet', queryparams:{"active":"queryjzxx"}, nowrap: false,//当数据长度超出列宽时将会自动截取 fit:true,//自动折叠容器的大小将填充父容器 showfooter:true,//显示视图的页脚 striped:true, //隔行变色 pagination:true,//开启分页 pagesize:curpagesize,//每页查看的记录数量 singleselect:true,//开启单选模式 pagenumber:curpagenumber,//初始的页面为第一页 rownumbers:true,//显示行数 fitcolumns: true,//自适应 fit:true, width:'100%', nowrap:false, striped:true, pagesize:20, pagenumber:1, showfooter:true, rownumbers:true, singleselect:true, pagination:true, fitcolumns:false, //不使用后台排序 remotesort :false, async:false, //下面是表单中加载显示的信息 columns:[[ {field:'姓名',align:'center',title:'姓名',width:fillsize(0.1)}, {field:'班级或部门',align:'center',title:'班级/部门',width:fillsize(0.16)}, {field:'主诉与症状',align:'center',title:'主诉与症状',width:fillsize(0.15), formatter:function(value){ for(var i=0; i<lodata.length; i++){ if (lodata[i].combovalue == value) { return lodata[i].comboname; } } return value; }}, {field:'病历类型',align:'center',title:'类型',width:fillsize(0.1), formatter:function(value,rec){ var bllx=""; if(rec.病历类型=='1'){ bllx="初诊"; }else{ bllx="复诊"; } return bllx; } }, {field:'就诊医生',align:'center',title:'就诊医生',width:fillsize(0.1)}, {field:'就诊时间',align:'center',title:'就诊时间',width:fillsize(0.2)}, {field:'info',align:'center',title:'操作',width:fillsize(0.1), formatter:function(value,rec){ var info='<input type="button" class="btn btn-primary" id="quebl" style="width:60px;" value="详情" onclick="openpersonblsy(\''+rec.就诊编号+'\',\''+rec.卡号+'\')"">'; return info; } } ]], //双击某行时触发 ondblclickrow:function(rowindex,rowdata){ }, //读取datagrid之前加载 onbeforeload:function(){}, //单击某行时触发 onclickrow:function(rowindex,rowdata){ rowxx = rowdata; }, //加载成功后触发 onloadsuccess: function(data){ ikeycode = ''; row = ''; curpagenumber = $(this).datagrid('options').pagenumber; curpagesize = $(this).datagrid('options').pagesize; }, error:function(data){} }); } //工具栏按钮调用方法,传入按钮的id@id 当前按钮点击事件 function dotoolbar(itoolbar){ //导出个人信息excl表格 if(itoolbar == 'outputgrxx'){ $('#active2').val('outputgrxx');//传隐藏值active $("#form3").submit();//表单提交方法 } } //提交的表单 $('#form3').form({ //定位到servlet位置的url url:'<%=request.getcontextpath()%>/importbean_servlet', //当点击事件后触发的事件 onsubmit: function(data){ return $(this).form('validate');//验证 }, //当点击事件并成功提交后触发的事件 success:function(data){ var json = eval("("+data+")"); if(json[0].msg == '文件生成成功'){ //下载文件到本地 $("#exportiframe").attr("src", '<%=request.getcontextpath()%>/download.jsp?filepath=' + encodeuricomponent(json[0].filepath)); $('#grxxinfodialog').dialog("close"); }else{ alertmsg(json[0].msg); } } }); //进行数据填充到个人信息弹窗,jzbh:就诊编号,kh:卡号 function openpersonblsy(jzbh,kh){ $('#grxxinfodialog').dialog({ title:"个人详细信息", }); $.ajax({ type : "post", url : '<%=request.getcontextpath()%>/importbean_servlet', data : 'active=queryjzxx&jzbh='+jzbh+"&kh="+kh, datatype:"json", success : function(data){ $("#jzbh_dc").val(data.rows[0].就诊编号); $("#kh_dc").val(data.rows[0].卡号); $("#brxm_dc").html(data.rows[0].姓名); $("#bjbm_dc").html(data.rows[0].班级或部门); $("#jzys_dc").val(data.rows[0].就诊医生); $("#jzsj_dc").val(data.rows[0].就诊时间); $("#ct_dc").val(data.rows[0].查体); $("#zdjg_dc").val(data.rows[0].诊断结果); $("#zlyj_dc").val(data.rows[0].诊疗意见); $("#zyyy_dc").val(data.rows[0].转院原因); $("#zzyy_dc").val(data.rows[0].转诊医院); $("#zzys_dc").val(data.rows[0].转诊医生); $("#zysj_dc").val(data.rows[0].转院时间); if (data.rows[0].是否隔离=='0') { $('#sfgl_dc').val('否'); }else{ $('#sfgl_dc').val('是'); } if(data.rows[0].人员类型=='1'){ $("#srylx_dc").val('学生'); }else{ $('#srylx_dc').val('老师'); } if(data.rows[0].病历类型=='1'){ $('#bllx_dc').val('初诊'); }else{ $('#bllx_dc').val('复诊'); } if(data.rows[0].转院原因!=''&&data.rows[0].转诊医院!=''){ $("#sfzy_dc").val('是'); }else{ $("#sfzy_dc").val('否'); } for(var i=0; i<lodata.length; i++){ if (lodata[i].combovalue == data.rows[0].主诉与症状) { $('#zsyzz_dc').val(lodata[i].comboname); } } //表单禁用 $('#jzys_dc').attr('readonly',true); $('#ct_dc').attr('readonly',true); $('#zdjg_dc').attr('readonly',true); $("#jzsj_dc").attr('readonly',true); $('#zlyj_dc').attr('readonly',true); $('#zyyy_dc').attr('readonly',true); $('#zzyy_dc').attr('readonly',true); $('#zzys_dc').attr('readonly',true); $("#zysj_dc").attr('readonly',true); $('#sfgl_dc').attr('readonly',true); $('#zsyzz_dc').attr('readonly',true); $('#srylx_dc').attr('readonly',true); $('#bllx_dc').attr('readonly',true); $('#sfzy_dc').attr('readonly',true); $('#grxxinfodialog').dialog('open'); } }); } </script>