// 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
//指定頁面區(qū)域內容導入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');"/>
該文章在 2010/8/18 0:46:03 編輯過