前台用extjs后台用java.如何导出excel报表

来源:百度知道 编辑:UC知道 时间:2024/06/01 14:10:05
在前台从grid取得员工的信息传到后到台生成报表。求前台向后台传递数据的code和后台java实现报表的完整的code。。。
小弟菜手上路
多谢了

前台
new Ext.Button({
text:'导出EXCEL',
handler:function(){
var appWindow = window.open("getExecl.do"); //调action得到数据生成execl格式的数据,response发往前台
appWindow.focus();
}
})

后台: filename是导出的文件名,heads是excel表头,datalist是数据
public void createExcelStream(HttpServletResponse response,String filename,String[] heads,List<String[]> datalist){
try{
OutputStream os = response.getOutputStream();
WritableWorkbook wbook = Workbook.createWorkbook(os);
WritableSheet wsheet = wbook.createSheet(filename, 0);
for(int i=0 ; i<heads.length ; i++) {
Label label =new Label(i,0 ,heads[i]);
wsheet.addCell(label);
}
for(int i=0 ;i<datalist.size();i++) {
for(int j=0 ; j<datalist.get(i).length ; j++){
Label label =new Label(j,i+1 ,datalist.get(i)[j]);
wsheet.addCell(label);
}
}