<span style="font-size: medium;">function outputAddress(grid){ try { var xls = new ActiveXObject("Excel.Application"); } catch (e) { alert("打印该表,必须安装Excel软件,且浏览器须使用“ActiveX 控件”。"); //return ""; } xls.visible = true; //表示excel为可见 var xlBook = xls.Workbooks.Add; var xlSheet = xlBook.Worksheets(1); var cm = grid.getColumnModel(); var colCount = cm.getColumnCount(); var temp_obj = []; //isHidden()为true表示隐藏 //临时数组,存放所有当前显示列的下标 for (i = 1; i < colCount; i++) { if (cm.isHidden(i) == true) { } else { temp_obj.push(i); } } for (i = 1; i <= temp_obj.length - 2; i++) { //显示列的标题 xlSheet.Cells(1, i).Value = cm.getColumnHeader(temp_obj[i - 1]); } var store = grid.getStore(); var recordCount = store.getCount(); var view = grid.getView(); for (i = 1; i <= recordCount; i++) { for (j = 1; j <= temp_obj.length; j++) { //EXCEL数据从第二行开始,row = i + 1; xlSheet.Cells(i + 1, j).Value = view.getCell(i - 1, temp_obj[j - 1]).innerText; } } xlSheet.Columns.AutoFit; xls.ActiveWindow.Zoom = 75
xls.UserControl = true; xls = null; xlBook = null; xlSheet = null; } </span>//不可省略,否则出问题 表示excel交由用户控制
ext.grid导出excel
最新推荐文章于 2024-09-10 14:14:32 发布