请描述更清晰
是点击页面上的保存 还是用户自己用浏览器自带的保存页面?
如果是前者 缺点是旧的浏览器用不了
SaveAsFile = function(N,C){
var A,Event
arguments.length < 2 && (C = N,N = '')
Event = document.createEvent('HTMLEvents')
Event.initEvent('click',!9,!9)
A = document.createElement('a')
A.setAttribute('download',N || '')
A.setAttribute('href',URL.createObjectURL(new Blob([C])))
A.dispatchEvent(Event)
}
SaveAsFile('Data','a\tb\tc\r\n0\t1\t2\r\n8\t\9\t3')
js导出excel和word都可以:JavaScript导出Table到Word和Excel
// JavaScript Document
//js代码
//导出到excel
function AutomateExcel(tableid){
var elTable = document.getElementById(tableid)//要导出的table id。
var oRangeRef = document.body.createTextRange()
oRangeRef.moveToElementText(elTable)
oRangeRef.execCommand("Copy")
var appExcel = new ActiveXObject("Excel.Application")
appExcel.Workbooks.Add().Worksheets.Item(1).Paste()
appExcel.Visible = true
appExcel = null
}
//导出到word
//指定页面区域内容导入Word
function AllAreaWord(tableid)
{
var elTable = document.getElementById(tableid)
var sel = document.body.createTextRange()
sel.moveToElementText(elTable)
sel.execCommand("Copy")
var oWD = new ActiveXObject("Word.Application")
var oDC = oWD.Documents.Add("",0,1)
var orange =oDC.Range(0,1)
//sel.select()
orange.Paste()
oWD.Application.Visible = true
oWD = null
}
调用方法:
<input name="word" type="button" value="导出到word" onclick="AllAreaWord('tableid')" /><input name="excel" type="button" value="导出到excel" onclick="AutomateExcel('tableid')"/>
function method1() {//整个表格拷贝到EXCEL中 var curTbl = document.getElementById("hgreport1MngTb")var oXL = new ActiveXObject("Excel.Application")//创建AX对象excel var oWB = oXL.Workbooks.A