ext导出excel

Ext导出excel很麻烦的,我们可以打开一个window.open()或window.location.href=''发送请求;把操作excel的工作交给后台的action处理就行了
[b]JS代码:[/b]
var grid =new Ext.grid.GridPanel({
	region:'center',
	store:store,
	cm:cm,
    tbar : [{
			text : "导出",
			iconCls:"post",
			handler :[i][b]exportToExcel[/b][/i]
		}]		
});
	var resultView = new Ext.Viewport( {
		layout : 'border',
		items : [grid]
	});
}
//导出excel表
function [i][b]exportToExcel[/b][/i](){
	var appWindow = window.open("xxx.action", 
		"menubar=0,scrollbar=0,resizable=1,channelmode=1,location=0,status=1");
	appWindow.focus();
//也可以用location.href来发送请求
//window.location.href="xxx.action?ids=123456";
}

[b]action代码:[/b]
public boolean exportToExcel(HttpServletResponse response, List list)
			throws Exception {

		OutputStream os = response.getOutputStream();
		WritableWorkbook wbook = Workbook.createWorkbook(os);
		WritableSheet wsheet = wbook.createSheet("合同信息", 0);
		Label label =new  Label(0,0 ,"test"); 
		Label label1 =new  Label(0,1 ,"test1"); 
		wsheet.addCell(label);  
		wsheet.addCell(label1); 
		response.setHeader("Content-disposition","attachment; filename=contract.xls");
		response.setContentType("application/vnd.ms-excel");
		wbook.write(); // 写入文件
		wbook.close();
		os.close(); // close outputStream

		return true;
	}

你可能感兴趣的:(工作,Excel,OS,ext)