ie浏览器使用js导出网页到excel并打印
在一些要求不是很高的小项目中,可以使用一些虽不是通用且不是新技术但是确实可以很好实现功能的技术来实现这些功能。这样系统不是显示的很复杂,且可以方便维护。
新建一个exportPrint.html页面,里面的代码如下所示,就可以实现导出到Excel和打印网页。
<html>
<head>
<title>IE浏览器使用JS技术导出到Excel和打印</title>
<style>
.table_stat{
border-right:0px;
border-bottom:0px;
border-left:1pxsolid#819BD8;
border-top:1pxsolid#819BD8;
}
.td_stat{
border-right:1pxsolid#819BD8;
border-bottom:1pxsolid#819BD8;
}
</style>
</head>
<body>
<objectclassid="CLSID:8856F961-340A-11DO-A96B-00C04FD705A2"height="0"id="WebBrowser"width="0"></object>
<tablewidth="100%"align="center"border="0"cellpadding="0"cellspacing="0"style="text-align:center;"class="table_stat">
<tr>
<tdid="title"align="center"nowrap="nowrap"class="td_stat"colspan="2">
用户信息
</td>
</tr>
<tr>
<tdid="title"align="center"nowrap="nowrap"class="td_stat"colspan="1">
姓名
</td>
<tdid="title"align="center"nowrap="nowrap"class="td_stat"colspan="1">
张三
</td>
</tr>
<tr>
<tdid="title"align="center"nowrap="nowrap"class="td_stat"colspan="2">
<inputtype="button"id="export"value="导出"onclick="javascript:exportToExcel();">
<inputtype="button"id="print"value="打印"onclick="javascript:print();">
</td>
</tr>
</table>
</body>
</html>
<scripttype="text/javaScript">
//导出到Excel
functionexportToExcel(){
if(document.getElementById("title")){
try{
varoRangeRef=document.body.createTextRange();
oRangeRef.execCommand("Copy");
varappExcel=newActiveXObject("Excel.Application");
appExcel.visible=true;
appExcel.Workbooks.Add().WorkSheets.Item(1).Paste();
}catch(e){
alert("出错啦!可能是浏览器或者是数据量太大咯哦!");
return;
}
appExcel=null;
oRangeRef=null;
}
}
//打印
functionprint(){
if(document.getElementById("title")){
varexport=document.getElementById("export");
varprint=document.getElementById("print");
try{
export.style.display="none";
print.style.display="none";
document.all.WebBrowser.ExecWB(6,1);
}catch(e){
alert("出错啦!可能是浏览器或者是数据量太大咯哦!");
return;
}
export.style.display="";
print.style.display="";
}
}
</script>
相关文章
- Fabric.js 使用纯色遮挡画布(前景色)
- wpsword表格转换成excel表格_wps文档表格怎么转换成wps表格
- 导出的Excel名字乱码_恢复的excel文件乱码
- excel宏 java,Microsoft Excel宏运行Java程序
- JS设置定时器_js设置定时器
- Excel公式:基于层次等级求和
- 疯狂的Excel公式,只为条件求和
- Excel函数:SORT函数与SORTBY函数
- 使用POI生成Excel文件,可以自动调整excel列宽详解编程语言
- MySQL查询结果导出至Excel:一步到位(mysql查询结果导出excel)
- 利用mongodb快速导出Excel文件(mongodb导出excel)
- 快速完成:从Excel导入Oracle数据库(excel导入oracle数据库)
- 文件Linux下如何打开Excel文件(linux打开excel)
- 数据库用Excel快速导入Oracle数据库(excel导入oracle)
- 极速提升业务效率:利用Excel快速导入Oracle数据库(excel数据导入oracle)
- MYSQL与EXCEL:实现数据管理的双重力量(mysql与excel)
- 使用JS在网页中连接Oracle数据库(js网页链接oracle)
- 数据JS技术实现实时获取Oracle数据(js实时获取oracle)
- JS将文件传输至MySQL数据库(.js传文件至mysql)
- 实现Redis数据批量导出至Excel(redis 转excel)
- asp.netGridView导出到Excel代码
- CSS和JS标签style属性对照表(方便js开发的朋友)
- js导入导出excel(实例代码)
- 通过复制Table生成word和excel的javascript代码
- JS将所有对象s的属性复制给对象r(原生js+jquery)
- 不到30行JS代码实现Excel表格的方法
- ASP.NET使用GridView导出Excel实现方法