博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
js把网页内容导入word、Excel中
阅读量:5911 次
发布时间:2019-06-19

本文共 2067 字,大约阅读时间需要 6 分钟。

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">
<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" οnclick="javascript:AllAreaWord();" value="导出页面指定区域内容到Word"></input>
            <input type="button" οnclick="javascript:AllAreaExcel();" value="导出页面指定区域内容到Excel"></input>
            <input type="button" οnclick="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>

转载地址:http://yzmpx.baihongyu.com/

你可能感兴趣的文章
Linux系统启动流程详解
查看>>
我的友情链接
查看>>
Magento(CE1.X)自带模块解析五
查看>>
linux基础
查看>>
Factory Method模式 (一)
查看>>
java正则表达式的学习
查看>>
Linux 环境变量的配置解决(-bash: jps: command not found)问题
查看>>
redis遇到过的问题汇总(持续更新)
查看>>
组策略无法正常应用
查看>>
[转载]Monit:开源服务器监控工具
查看>>
Linux 打印 颜色显示
查看>>
dubbo请求调用过程分析
查看>>
Oracle学习(一):Oracle数据库基础
查看>>
27. Python对Mysql的操作(2)
查看>>
Linux 中用 strace 追踪系统调用和信号值
查看>>
JAVASE贪吃蛇开发记录
查看>>
mysql全文索引____ft_min_word_len
查看>>
Shiro的记住我功能失效原因
查看>>
yum方式安装mysql报错找不到mysql.sock
查看>>
PrestaShop支付接口-网银在线支付,在线支付收款,外贸收款
查看>>