利用剪切板将网页数据导入到excel

此方法最开始的想法是要将datagrid的数据连格式一起导入到excel

<html>

<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
<script>

function ClipBoard()
{
document.getElementById("holdtext").innerText= copytext.innerHTML;
Copied = document.getElementById("holdtext").createTextRange();
Copied.execCommand("Copy");

}
function AutomateExcel()
{
// Start Excel and get Application object.
 var oXL = new ActiveXObject("Excel.Application");
// Get a new workbook.
var oWB = oXL.Workbooks.Add();
var oSheet = oWB.ActiveSheet;
oSheet.Cells(2,1).select();
oSheet.Paste;
oXL.Visible = true;
oXL.UserControl = true;
}

</script>
</head>

<body>
<form>


<span ID="copytext">
<table border="1" width="100%" id="table1">
 <tr>
  <td><font color="#FF00FF">qw</font></td>
  <td><font color="#FF00FF">w</font></td>
  <td>e3</td>
 </tr>
 <tr>
  <td>a</td>
  <td>a</td>
  <td>d</td>
 </tr>
</table>
</span>
<TEXTAREA ID="holdtext" STYLE="display:none;">
</TEXTAREA>
<input type=button onclick ="ClipBoard()" value="copy"><input type=button onclick ="AutomateExcel()" value="Export"></form>
</body>

</html>

下面是从网上找到的调用clipboard的示例

//Copytext to clipboard- by Gennero (patrice.gennero@voila.fr)
//Submited to DynamicDrive.com
//Visit http://www.dynamicdrive.com for this script

bBool=false
var copiedtext=""
var tempstore=""

function initiatecopy() {
bBool=true;
}

function copyit() {
if (bBool) {
tempstore=copiedtext
document.execCommand("Copy")
copiedtext=window.clipboardData.getData("Text");
if (tempstore!=copiedtext) {
alert(copiedtext);
}
bBool=false;
}
}

document.onselectionchange = initiatecopy
document.onmouseup = copyit

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值