日期:2014-05-17 浏览次数:20961 次
function doOut(gridid) { var gView = Efs.getExt(gridid).getView(); var rows = gView.getRows().length; //行数 var columncount = Efs.getExt(gridid).getColumnModel().getColumnCount(); //列数 var r = 1; if (gView.getHeaderCell(1).innerText == " ") { r = 2; } try { var oXL = new ActiveXObject("Excel.Application"); //创建AX对象excel var oWB = oXL.Workbooks.Add(); //获取workbook对象 var oSheet = oWB.ActiveSheet; //激活当前sheet catch(e){ alert("创建excel对象失败,请确认已经安装了excel软件!"); return false; } var i = r; for (var j= 1; i < columncount; j++,i++) { oSheet.Cells(1, j).value = gView.getHeaderCell(i).innerText; } for (var k = 0, l = 2; k < rows; k++, l++) { i = r; for (var x = 1; i < columncount; x++, i++) { var y = gView.getCell(k, i).firstChild.innerHTML; if (y == null || y == " ") { y = ""; } oSheet.Cells(l, x).value = "'"+y; } } oXL.Visible = true; oXL.Quit(); oXL = null; }