其他分享
首页 > 其他分享> > JXLS使用

JXLS使用

作者:互联网

public void searchexport(String idcards, HttpServletRequest request, HttpServletResponse response,String id) {
  OutputStream out = null;
  Map map = new HashMap();
  XLSTransformer transformer = new XLSTransformer();
  InputStream is = UserInfoController.class.getClassLoader().getResourceAsStream("template" + File.separator + "excel" +File.separator + "export" + File.separator + "search.xls");
  String downloadFileName = "";
  String fileName = "成绩表";
  List list = null;
  try {
    map = testPaperService.searchexport(idcards,id);
  } catch(QueryException e1) {
    e1.printStackTrace();
  }
  map.put("title", fileName);
  map.put("date", list);
try {
  downloadFileName = new String(fileName.getBytes("gbk"), "ISO-8859-1");
  response.reset();
  response.setContentType("application/octet-stream; charset=utf-8");
  response.setHeader("Content-Disposition", "attachment;filename=\"" + downloadFileName + ".xls\"");

  out = response.getOutputStream()

  org.apache.poi.ss.usermodel.Workbook workbook = transformer.transformXLS(is, map);
  workbook.write(out);
  } catch(Exception e) {
  e.printStackTrace();
  }
}

 

标签:map,String,JXLS,fileName,使用,new,response,out
来源: https://www.cnblogs.com/douhuan/p/11130270.html