日期:2014-05-17 浏览次数:20946 次
@org.springframework.stereotype.Controller(value = "interviewLogController")
@Scope(value = "prototype")
public class InterviewLogController implements Controller {
@Resource(name="InterviewLogBiz")
private InterviewLogBiz interviewLogBiz;
@RequestMapping(value = "ExportInterviewLogQuery2")
public void exportInterviewExcel2(HttpServletRequest req,
HttpServletResponse resp) throws Exception {
Interview interview = new Interview();
//File file = new File(getServletContext().getRealPath("WEB-INF/book.jpg"));
resp.setContentType("octets/stream");
resp.addHeader("Content-Disposition",
"attachment;filename=学员访谈记录表.xls");
ExportExcel<Interview> ex = new ExportExcel<Interview>();
//ExportExcel<T> ex = new ExportExcel<T>();
//创建列
String[] headers = { "姓名", "访谈时间", "电话或当面访谈内容", "备注" };
//从数据库中读取数据
List<Interview> dataset = new ArrayList<Interview>();
String csid = req.getParameter("csid");
interview.setCsid(csid);
if(csid!=null && csid!=""){
dataset = interviewLogBiz.query(interview.getCsid());
interview.setName(dataset.get(0).getName());
interview.setIinterviewTime(dataset.get(0).getIinterviewTime());
interview.setIcontent(dataset.get(0).getIcontent());
interview.setInterviewWay(dataset.get(0).getInterviewWay());
}else{
return ;
}
try {
dataset.add(new Interview(interview.getName(), interview.getIinterviewTime(),
interview.getIcontent(), interview.getInterviewWay()));
OutputStream out = resp.getOutputStream();
ex.exportExcel(headers, dataset, out);
out.close();
System.out.println("excel导出成功!");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch ( spring国际化不能阻截.jsp的请求