直接把EXCEL粘贴到网页上

经常碰到需要通过EXCEL往系统中上传数据的情况。

当然我们可以直接上传EXCEL,然后用PHP分析。但大家都知道,PHP分析EXCEL还是比较麻烦的!

不知道大家有没有想过直接把EXCEL粘贴到页面上,然后提交表单呢?

下面这段程序可以给大家提供个思路。

从EXCEL里复制部分单元格,在这个页面中点击“粘贴”按钮,EXCEL的内容就贴到网页上了。根据需要,可以修改下面的代码,在里面添加form或input,以达到直接生成表单的目的。

演示页面:http://www.enjoyphp.com/myfile/excel2web.html



<html>
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
<head>
<script language="javascript">
function clip() {
   
    var clipText = window.clipboardData.getData('Text');

   
    clipRows = clipText.split(String.fromCharCode(13));

   
    for (i=0; i<clipRows.length; i++) {
        clipRows[i] = clipRows[i].split(String.fromCharCode(9));
    }

   
    newTable = document.createElement("table")
    newTable.border = 1;
    for (i=0; i<clipRows.length - 1; i++) {

        newRow = newTable.insertRow();

        for (j=0; j<clipRows[i].length; j++) {
                newCell = newRow.insertCell();
                if (clipRows[i][j].length == 0) {
                        newCell.innerText = ' ';
                }
                else {
                        newCell.innerText = clipRows[i][j];
                }
        }
    }

    document.body.appendChild(newTable);
}
</script>
</head>
<body>
从EXCEL中复制一个表格,然后点击本页的“粘贴”按钮。<br/>
<input type="button" onclick="clip()" value='粘贴' />
</body>
</html>



( ! ) Warning: Missing argument 1 for cwppos_show_review(), called in /data/www/enjoyphp/wp-content/themes/flat/content-single.php on line 29 and defined in /data/www/enjoyphp/wp-content/plugins/wp-product-review/includes/legacy.php on line 18
Call Stack
#TimeMemoryFunctionLocation
10.0000355176{main}( ).../index.php:0
20.0001355464require( '/data/www/enjoyphp/wp-blog-header.php' ).../index.php:17
30.171810162968require_once( '/data/www/enjoyphp/wp-includes/template-loader.php' ).../wp-blog-header.php:19
40.173110234112include( '/data/www/enjoyphp/wp-content/themes/flat/single.php' ).../template-loader.php:74
50.278810791848get_template_part( ).../single.php:5
60.278810792368locate_template( ).../general-template.php:167
70.278810792464load_template( ).../template.php:643
80.278910792848require( '/data/www/enjoyphp/wp-content/themes/flat/content-single.php' ).../template.php:686
90.287310777960cwppos_show_review( ).../content-single.php:29

1 评论

发表评论

电子邮件地址不会被公开。 必填项已用*标注