日期:2014-05-16  浏览次数:20363 次

如何拆分剪贴板中复制的Excel数据到数组,并赋值到下方的table中?
<script>
        function   Paste(){
                var   ClipboardText=window.clipboardData.getData( 'Text ');                
                var   ClipboardText=ClipboardText.replace(/[\r\n]/g,   ", ");
                var   Rows=ClipboardText.split( ", ");
                for(var   iRow=0;iRow <Rows.length;iRow++)   {
                        var   Cells=Rows[iRow].split( '\t ');
                        for(var   iCol=0;iCol <Cells.length;iCol++)
                                alert(Cells[iCol]);
                }
        }
</script>

<input   id= "Test "> </input> <input   type= "button "   value= "Paste "   onclick= "Paste(); "> </input>
<table>
<tr> <td> <input> </input> <input> </input> </td> </tr>
<tr> <td> <input> </input> <input> </input> </td> </tr>
</table>


------解决方案--------------------
<html>
<head>
<title> </title>
<script language= "JavaScript ">
function Paste()
{
var tab = window.document.getElementById( "TableExcel ");
alert(window.clipboardData.getData( 'Text '));
var exRows = window.clipboardData.getData( 'Text ').split( "\r ");
for(var i = 0; i < exRows.length; i++)
{
if(i == tab.rows.length)
{
break;
}
alert(i)
var row = tab.rows[i];
var exCells = exRows[i].split( "\t ");
for(var j = 0; j < exCells.length; j++)
{
if(j == row.cells.length)
{
continue;
}
row.cells[j].childNodes[0].value = exCells[j];
}
}
}

</script>
</head>
<body>
<input id= "paset " type= "button " value= "Paste " onclick= "Paste(); "> </input>
<table id= "TableExcel ">
<tr> <td> <input> </input> </td> <td> <input> </input> </td> </tr>
<tr> <td> <input> </input> </td> <td> <input> </input> </td> </tr>
</table>
</body>
</html>


IE6.0中测试通过
------解决方案--------------------
<html>
<head>
<title> </title>
<script language= "JavaScript ">
function Paste(){
var tab = window.document.getElementById( "TableExcel ");
while(tab.rows.length > 0){
tab.deleteRow(0);
}
var exRows =