jsp中table内容导出到word或excel

<html>
    <head>
    <title>projectGovPlace_list.jsp</title>
        <meta http-equiv="pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="expires" content="0">
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
        <meta http-equiv="description" content="This is my page">
        <link href="css/strongpt.css" rel="stylesheet" type="text/css">
    </head>
    <body>
        <table width="100%" border="0" align="center" cellPadding="0"
            cellSpacing="0" id="datatable">
            <tr align="center">
                <td width="4%" class="table_title">
                    #
                </td>
                <td width="14%" class="table_title">
                   项目
                </td>
            </tr>
            <tr align="center" class="table_2">
                <td align="center">
                    <input name="classId" value="8913" type="radio" />
                </td>
                <td>
                    &nbsp;
                    <span>项目</span>
                </td>
            </tr>
            <tr align="center" class="table_1">
                <td align="center">
                    <input name="classId" value="005" type="radio" />
                </td>
                <td>
                    &nbsp;
                    <span>其他</span>
                </td>
            </tr>
            <tr align="center" class="table_2">
                <td align="center">
                    <input name="classId" value="004" type="radio" />
                </td>
                <td>
                    &nbsp;
                    <span>单位自筹</span>
                </td>
            </tr>
            <tr align="center" class="table_1">
                <td align="center">
                    <input name="classId" value="003" type="radio" />
                </td>
                <td>
                    &nbsp;
                    <span>银行贷款</span>
                </td>
            </tr>
            <tr align="center" class="table_2">
                <td align="center">
                    <input name="classId" value="002" type="radio" />
                </td>
                <td>
                    &nbsp;
                    <span>开行贷款</span>
                </td>
            </tr>
            <tr align="center" class="table_1">
                <td align="center">
                    <input name="classId" value="001" type="radio" />
                </td>
                <td>
                    &nbsp;
                    <span>市本级财政</span>
                </td>
            </tr>
        </table>
        <input type="button" onClick="return AutomateExcel();"
            value="导出到EXCEL" />
        </br>
        <input type="button" onClick="return AllAreaWord();" value="导出到WORD" />
        <script language="javascript">
            function AutomateExcel(){
                var elTable = document.getElementById("datatable"); //要导出的table id。
                var oRangeRef = document.body.createTextRange(); 
                oRangeRef.moveToElementText(elTable); 
                oRangeRef.execCommand("Copy");
                var appExcel = new ActiveXObject("Excel.Application");
                appExcel.Workbooks.Add().Worksheets.Item(1).Paste(); 
                appExcel.Visible = true; 
                appExcel = null;
            }
            //导出到word
            //指定页面区域内容导入Word
            function AllAreaWord(){
                var oWD = new ActiveXObject("Word.Application");
                var oDC = oWD.Documents.Add("",0,1);
                var orange =oDC.Range(0,1);
                var elTable = document.getElementById("datatable"); 
                var sel = document.body.createTextRange();
                sel.moveToElementText(elTable);
                //sel.select();
                sel.execCommand("Copy");
                orange.Paste();
                oWD.Application.Visible = true;
                oWD = null;
            }
        </script>
    </body>
</html>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值