JS导出Excel
js导出excel支持各种浏览器,本人亲测,支持IE火狐chrome 360等多种常用浏览器function method1(tableid) {//整个表格拷贝到EXCEL中tttif(getExplorer()=='ie') ttt{ ttttvar curTbl = document.getElementById(tableid); ttttvar oXL = new ActiveXObject("Excel.Application"); tttt//创建AX对象excel ttttvar oWB = oXL.Workbooks.Add(); tttt//获取workbook对象ttttvar xlsheet = oWB.Worksheets(1); tttt//激活当前sheet ttttvar sel = document.body.createTextRange(); ttttsel.moveToElementText(curTbl); tttt//把表格中的内容移到TextRange中ttttsel.select(); tttt//全选TextRange中内容ttttsel.execCommand("Copy"); tttt//复制TextRange中内容ttttxlsheet.Paste(); tttt//粘贴到活动的EXCEL中ttttoXL.Visible = true; tttt//设置excel可见属性tttttry { tttttvar fname = oXL.Application.GetSaveAsFilename("Excel.xls", "Excel Spreadsheets (*.xls), *.xls"); tttt} catch (e) { tttttprint("Nested catch caught " + e); tttt} finally { tttttoWB.SaveAs(fname); tttttoWB.Close(savechanges = false); ttttt//xls.visible = false; tttttoXL.Quit(); tttttoXL = null; ttttt//结束excel进程,退出完成ttttt//window.setInterval("Cleanup();",1); tttttidTmr = window.setInterval("Cleanup();", 1); tttt} tttt ttt} tttelse ttt{ tttttableToExcel('ta') ttt} }
3.25KB
文件大小:
评论区