zoukankan      html  css  js  c++  java
  • js把网页内容导入word、Excel中

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>无标题页</title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <table width="100%" border="1" id="PrintA">
                    <tr>
                        <td>
                            dfsdfds</td>
                        <td>
                            &dsfds</td>
                        <td>
                            &sdf;</td>
                        <td>
                            dsf</td>
                    </tr>
                    <tr>
                        <td>
                            dsf</td>
                        <td>
                            dsfds</td>
                        <td>
                            fsdfdsfdsf</td>
                        <td>
                            dsfs</td>
                    </tr>
                    <tr>
                        <td>
                            dsfds</td>
                        <td>
                            dsf</td>
                        <td>
                            dsfd</td>
                        <td>
                            sfds</td>
                    </tr>
                    <tr>
                        <td>
                            &nbsp;</td>
                        <td>
                            sdf</td>
                        <td>
                            fdsf</td>
                        <td>
                            &nbsp;</td>
                    </tr>
                </table>
                <input type="button" onclick="javascript:AllAreaWord();" value="导出页面指定区域内容到Word"></input>
                <input type="button" onclick="javascript:AllAreaExcel();" value="导出页面指定区域内容到Excel"></input>
                <input type="button" onclick="javascript:CellAreaExcel();" value="导出表单单元格内容到Excel"></input>

                <script type="text/javascript" language="javascript">

    //指定页面区域内容导入Excel

    function AllAreaExcel()

    {

    var oXL = new ActiveXObject("Excel.Application");

    var oWB = oXL.Workbooks.Add();

    var oSheet = oWB.ActiveSheet;

    var sel=document.body.createTextRange();

    sel.moveToElementText(PrintA);

    sel.select();

    sel.execCommand("Copy");

    oSheet.Paste();

    oXL.Visible = true;

    }

    //指定页面区域“单元格”内容导入Excel

    function CellAreaExcel()

    {

    var oXL = new ActiveXObject("Excel.Application");

    var oWB = oXL.Workbooks.Add();

    var oSheet = oWB.ActiveSheet;

    var Lenr = PrintA.rows.length;

    for (i=0;i<Lenr;i++)

    {

       var Lenc = PrintA.rows(i).cells.length;

       for (j=0;j<Lenc;j++)

       {

        oSheet.Cells(i+1,j+1).value = PrintA.rows(i).cells(j).innerText;

       }

    }

    oXL.Visible = true;

    }

    //指定页面区域内容导入Word

    function AllAreaWord()

    {

    var oWD = new ActiveXObject("Word.Application");

    var oDC = oWD.Documents.Add("",0,1);

    var oRange =oDC.Range(0,1);

    var sel = document.body.createTextRange();


    sel.moveToElementText(PrintA);

    sel.select();

    sel.execCommand("Copy");

    oRange.Paste();

    oWD.Application.Visible = true;

    //window.close();

    oWD.ActiveWindow.ActivePane.View.Type=3

    oWD.Application.close;

    }

                </script>

            </div>
        </form>
    </body>
    </html>

  • 相关阅读:
    Sky中国War3的旗帜
    2008流行趋势发布暨07届学生毕业秀(上海大学主办)
    随便写一下
    六一节——小朋友们快乐
    HEI
    Update my blog to improve my idea.
    由ipod引起的奇遇记
    加勒比海盗
    “老板娘”请客吃饭
    蚂蚁工坊
  • 原文地址:https://www.cnblogs.com/12go/p/2194517.html
Copyright © 2011-2022 走看看