js代码
<script language="javascript"> 

function OpenWord()...{ 
Layer1.style.border=0 
ExcelSheet = new ActiveXObject('word.Application'); 
ExcelSheet.Application.Visible = true; 
var mydoc=ExcelSheet.Documents.Add('',0,1); 
myRange =mydoc.Range(0,1) 
var sel=Layer1.document.body.createTextRange() 
sel.select() 
Layer1.document.execCommand('Copy') 
sel.moveEnd('character') 
myRange.Paste(); 
location.reload() 
ExcelSheet.ActiveWindow.ActivePane.View.Type=9 
} 
</script> 
html代码
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
<title>网页上内容导出到word</title> 
</head> 
<body> 
<div id="Layer1" > 
<input type=button name='button_export' title='导出到word' onclick=OpenWord() value=下载到word></div> 
</div> 
<table align="center" width="300" border="1" bordercolor="#2baeff" cellpadding="0" cellspacing="0" bgcolor="lightblue"> 
<Tr><Td>1</td><Td>2</td><Td>3</td></tr> 
<Tr><Td>4</td><Td>5</td><Td>6</td></tr> 
<Tr><Td>7</td><Td>8</td><Td>9</td></tr> 
</table> 
</body> 
</html> 
本文介绍了一种使用JavaScript将网页上的表格内容复制并粘贴到Word文档中的方法。通过创建Word应用程序对象并利用浏览器的复制粘贴功能实现数据转移,最后通过刷新页面来结束操作。
941

被折叠的 条评论
为什么被折叠?



