注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

忽尔今夏

人生中最大的敌人是自己......

 
 
 

日志

 
 

关于Excel数据的导出  

2010-03-31 11:18:32|  分类: JAVA |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

JSP

<script type="text/javascript">

  function doExcel(){
    window.location.href = "tsXsBasicInfo.do?operate=toExcel";
  }

</script>

......

<input name="button" type="button" value="Excel数据导出" onclick="doExcel()" />

......

 

Action

/**
  * 导出学生信息
  * @throws IOException
  */
 public ActionForward toExcel(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response) throws IOException {
  
  response.setContentType("application/msexcel;charset=UTF-8");
  response.setHeader("Content-disposition","inline; filename=CrouseInfo.xls");
  
  OutputStream os=response.getOutputStream();
  
  List crouseExcel=itsxsBasicInfoBiz.getAll();
  try {
   //创建一个工作簿
   WritableWorkbook workbook=Workbook.createWorkbook(os);
   
   WritableSheet sheet=workbook.createSheet("First Sheet",0);
   Label labelNum=new Label(0,0,"序号");
   sheet.addCell(labelNum);
   Label lblClassNum=new Label(1,0,"学生学号");
   sheet.addCell(lblClassNum);
   Label lblMasterTitle=new Label(2,0,"学生姓名");
   sheet.addCell(lblMasterTitle);
   Label lblTeacherTitle=new Label(3,0,"学生学院");
   sheet.addCell(lblTeacherTitle);
   Label lblReal=new Label(4,0,"学生专业");
   sheet.addCell(lblReal);
   Label lblTotal=new Label(5,0,"学生年级");
   sheet.addCell(lblTotal);
   Label lblRate=new Label(6,0,"学生班级");
   sheet.addCell(lblRate);
   Label lblWatchTitle=new Label(7,0,"电子邮件");
   sheet.addCell(lblWatchTitle);
   Label lblDateTitle=new Label(8,0,"家庭住址");
   sheet.addCell(lblDateTitle);
   Label lblDateTitle1=new Label(9,0,"备注");
   sheet.addCell(lblDateTitle1);
   for(int i=1;i<=crouseExcel.size();i++){
    TsXsBasicInfo call=(TsXsBasicInfo)crouseExcel.get(i-1);
    Number numId=new Number(0,i,i);
    sheet.addCell(numId);
    Number numClassNum=new Number(1,i,call.getStudentNum());
    sheet.addCell(numClassNum);
    Label lblMaster=new Label(2,i,call.getStuName());
    sheet.addCell(lblMaster);
    Label lblTeacher=new Label(3,i,call.getTsUnitCollage().getCollageName());
    sheet.addCell(lblTeacher);
    Label numReal=new Label(4,i,call.getTsUnitColledgeSpeciality().getSpecialityName());
    sheet.addCell(numReal);
    Label numTotal=new Label(5,i,call.getCurrentgread());
    sheet.addCell(numTotal);
    Label numRate=new Label(6,i,call.getClass().getName());
    sheet.addCell(numRate);
    Label lblWatch=new Label(7,i,call.getEmail());
    sheet.addCell(lblWatch);
    Label lblDate=new Label(8,i,call.getHomeLocus());
    sheet.addCell(lblDate);
    Label lblWatch1=new Label(9,i,call.getRemark());
    sheet.addCell(lblWatch1);
   }
    
   workbook.write();
   workbook.close();
   os.close();
  } catch (IOException e) {
   e.printStackTrace();
  } catch (RowsExceededException e) {
   e.printStackTrace();
  } catch (WriteException e) {
   e.printStackTrace();
  }
  
  return null;
  
 }

 

  评论这张
 
阅读(51)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017