核心JavaScript代码
<script type="text/javascript">
function bringToExcel(){
var pasteText="全部统计表 ";
pasteText=pasteText+document.all.ExcelBiao.innerHTML;
window.clipboardData.setData ("Text", pasteText);
var oXL = new ActiveXObject("Excel.Application");
oXL.Visible = true;
var oWB = oXL.Workbooks.Add();
var oSheet = oWB.ActiveSheet;
oSheet.Paste();
oXL.Visible = true;
oXL.UserControl = true;
}
//导出word
function OpenWord2(){
ExcelSheet = new ActiveXObject('Word.Application');
ExcelSheet.Application.Visible = true;
var mydoc=ExcelSheet.Documents.Add('',0,0);
myRange =mydoc.Range(0,1);
myRange =mydoc.Range(myRange.End-1,myRange.End);//设定起始点
var sel=document.body.createTextRange();
sel.moveToElementText(AoutWord);//设置要导出的表格名称
sel.select();
document.execCommand('Copy');
sel.moveEnd('character');
myRange.Paste();
myRange =mydoc.Range(myRange.End-1,myRange.End);
myRange.InsertAfter("\n");
ExcelSheet.ActiveWindow.View.TableGridlines = false;
}
</script>
具体看附件
ExportWordAndExcel