js导出表格到excel(合并头)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<div id="table1">
<div class="tbHeadFix">
<div class="theadDiv" id="table1_theadDiv"> <div class="theadDivBox">
<table id="ta">
<thead>
<tr class="font-size-12 tr_head" >
<th rowspan="2">
<div class="col col0">品号</div>
</th>
<th rowspan="2">
<div class="col col2">客户</div>
</th>
<th colspan="2">
<div class="col col3">1月</div>
</th>
<th colspan="2">
<div class="col col4">2月</div>
</th>
<th colspan="2">
<div class="col col5">3月</div>
</th>
<th colspan="2">
<div class="col col6">4月</div>
</th>
<th colspan="2">
<div class="col col7">5月</div>
</th>
<th colspan="2">
<div class="col col8">6月</div>
</th>
<th colspan="2">
<div class="col col9">7月</div>
</th>
<th colspan="2">
<div class="col col10">8月</div>
</th>
<th colspan="2">
<div class="col col11">9月</div>
</th>
<th colspan="2">
<div class="col col12">10月</div>
</th>
<th colspan="2">
<div class="col col13">11月</div>
</th>
<th colspan="2">
<div class="col col14">12月</div>
</th>
<th colspan="2">
<div class="col col15">小计</div>
</th>
</tr>
<tr class="font-size-12 tr_head" >
<th>
<div class="mcol">预算</div>
</th>
<th>
<div class="mcol">决算</div>
</th>
<th>
<div class="mcol">预算</div>
</th>
<th>
<div class="mcol">决算</div>
</th>
<th>
<div class="mcol">预算</div>
</th>
<th>
<div class="mcol">决算</div>
</th>
<th>
<div class="mcol">预算</div>
</th>
<th>
<div class="mcol">决算</div>
</th>
<th>
<div class="mcol">预算</div>
</th>
<th>
<div class="mcol">决算</div>
</th>
<th>
<div class="mcol">预算</div>
</th>
<th>
<div class="mcol">决算</div>
</th>
<th>
<div class="mcol">预算</div>
</th>
<th>
<div class="mcol">决算</div>
</th>
<th>
<div class="mcol">预算</div>
</th>
<th>
<div class="mcol">决算</div>
</th>
<th>
<div class="mcol">预算</div>
</th>
<th>
<div class="mcol">决算</div>
</th>
<th>
<div class="mcol">预算</div>
</th>
<th>
<div class="mcol">决算</div>
</th>
<th>
<div class="mcol">预算</div>
</th>
<th>
<div class="mcol">决算</div>
</th>
<th>
<div class="mcol">预算</div>
</th>
<th>
<div class="mcol">决算</div>
</th>
<th>
<div class="mcol">预算</div>
</th>
<th>
<div class="mcol">决算</div>
</th>
</tr>
</thead>
<tbody>
<tr class="font-size-12 tr_head" >
<th rowspan="2">
<div class="col col0">品号</div>
</th>
<th rowspan="2">
<div class="col col2">客户</div>
</th>
<th colspan="2">
<div class="col col3">1月</div>
</th>
<th colspan="2">
<div class="col col4">2月</div>
</th>
<th colspan="2">
<div class="col col5">3月</div>
</th>
<th colspan="2">
<div class="col col6">4月</div>
</th>
<th colspan="2">
<div class="col col7">5月</div>
</th>
<th colspan="2">
<div class="col col8">6月</div>
</th>
<th colspan="2">
<div class="col col9">7月</div>
</th>
<th colspan="2">
<div class="col col10">8月</div>
</th>
<th colspan="2">
<div class="col col11">9月</div>
</th>
<th colspan="2">
<div class="col col12">10月</div>
</th>
<th colspan="2">
<div class="col col13">11月</div>
</th>
<th colspan="2">
<div class="col col14">12月</div>
</th>
<th colspan="2">
<div class="col col15">小计</div>
</th>
</tr>
<tr class="font-size-12 tr_head" >
<th>
<div class="mcol">预算</div>
</th>
<th>
<div class="mcol">决算</div>
</th>
<th>
<div class="mcol">预算</div>
</th>
<th>
<div class="mcol">决算</div>
</th>
<th>
<div class="mcol">预算</div>
</th>
<th>
<div class="mcol">决算</div>
</th>
<th>
<div class="mcol">预算</div>
</th>
<th>
<div class="mcol">决算</div>
</th>
<th>
<div class="mcol">预算</div>
</th>
<th>
<div class="mcol">决算</div>
</th>
<th>
<div class="mcol">预算</div>
</th>
<th>
<div class="mcol">决算</div>
</th>
<th>
<div class="mcol">预算</div>
</th>
<th>
<div class="mcol">决算</div>
</th>
<th>
<div class="mcol">预算</div>
</th>
<th>
<div class="mcol">决算</div>
</th>
<th>
<div class="mcol">预算</div>
</th>
<th>
<div class="mcol">决算</div>
</th>
<th>
<div class="mcol">预算</div>
</th>
<th>
<div class="mcol">决算</div>
</th>
<th>
<div class="mcol">预算</div>
</th>
<th>
<div class="mcol">决算</div>
</th>
<th>
<div class="mcol">预算</div>
</th>
<th>
<div class="mcol">决算</div>
</th>
<th>
<div class="mcol">预算</div>
</th>
<th>
<div class="mcol">决算</div>
</th>
</tr>
</tbody>
</table>
</div>
</div> <!--表格1结束-->
<button onclick="javascript:method1('ta')">导出EXCEL</button>
<script type="text/javascript">
var idTmr;
function getExplorer() {
var explorer = window.navigator.userAgent ;
//ie
if (explorer.indexOf("MSIE") >= 0) {
return 'ie';
}
//firefox
else if (explorer.indexOf("Firefox") >= 0) {
return 'Firefox';
}
//Chrome
else if(explorer.indexOf("Chrome") >= 0){
return 'Chrome';
}
//Opera
else if(explorer.indexOf("Opera") >= 0){
return 'Opera';
}
//Safari
else if(explorer.indexOf("Safari") >= 0){
return 'Safari';
}
}
function method1(tableid) {//整个表格拷贝到EXCEL中
if(getExplorer()=='ie')
{
var curTbl = document.getElementById(tableid);
var oXL = new ActiveXObject("Excel.Application"); //创建AX对象excel
var oWB = oXL.Workbooks.Add();
//获取workbook对象
var xlsheet = oWB.Worksheets(1);
//激活当前sheet
var sel = document.body.createTextRange();
sel.moveToElementText(curTbl);
//把表格中的内容移到TextRange中
sel.select();
//全选TextRange中内容
sel.execCommand("Copy");
//复制TextRange中内容
xlsheet.Paste();
//粘贴到活动的EXCEL中
oXL.Visible = true;
//设置excel可见属性 try {
var fname = oXL.Application.GetSaveAsFilename("Excel.xls", "Excel Spreadsheets (*.xls), *.xls");
} catch (e) {
print("Nested catch caught " + e);
} finally {
oWB.SaveAs(fname); oWB.Close(savechanges = false);
//xls.visible = false;
oXL.Quit();
oXL = null;
//结束excel进程,退出完成
//window.setInterval("Cleanup();",1);
idTmr = window.setInterval("Cleanup();", 1); } }
else
{
tableToExcel('ta');
}
}
function Cleanup() {
window.clearInterval(idTmr);
CollectGarbage();
}
var tableToExcel = (function() {
var uri = 'data:application/vnd.ms-excel;base64,',
template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>',
base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) },
format = function(s, c) {
return s.replace(/{(\w+)}/g,
function(m, p) { return c[p]; }) }
return function(table, name) {
if (!table.nodeType) table = document.getElementById(table)
var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML}
window.location.href = uri + base64(format(template, ctx))
}
})();
</script>
</body>
</html>
js导出表格到excel(合并头)的更多相关文章
- 【js】js导出表格到excel
js: function method(tableid) //读取表格中每个单元到EXCEL中 { var curTbl = document.getElementById(tableid); var ...
- java代码导出数据到Excel、js导出数据到Excel(三)
jsp内容忽略,仅写个出发按钮: <button style="width: 100px" onclick="expertExcel()&quo ...
- JS导出、导入EXCEL(案例)
插件下载地址:http://oss.sheetjs.com/js-xlsx/xlsx.full.min.js 1.导出excel <!DOCTYPE html> <html> ...
- Vue 导出表格为Excel
放法有多种,我这里是直接转JSON数据为Excel. 1.既然要使用,那首先当然是安装依赖,在终端命令输入: npm install -S file-saver xlsx npm install -D ...
- JS 导出Table为excel的三种可行方法
[html] view plain copy<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" &q ...
- qt技巧--使用html导出表格替代excel
曾经为qt不能直接导出excel而困扰,后来经过深入了解,得知qt支持xml国际语言,html是xml的一种.html是做网页的,相信大家比较熟悉.所以使用html的<table ...
- php JS 导出表格特殊处理
但是这样导出身份证号会变为科学计数: 解决方法就是: 我们了解一下excel从web页面上导出的原理.当我们把这些数据发送到客户端时,我们想让客户端程序(浏览器)以excel的格式读取 它,所以把mi ...
- [转]纯js导出json到excel(支持chrome)
转自:http://blog.csdn.net/educast/article/details/52775559 function JSONToExcelConvertor(JSONData, Fil ...
- js导出表格数据
考虑到浏览器兼容性问题,采用原生js和后台交互下载网页数据 js: var table = $('.table-panel table'); // Header var tdData ="& ...
- js导出table到excel,同时兼容FF和IE
前台调用(第一个参数是table的id): <input value="导出" type="button" /> function toExcel( ...
随机推荐
- vue中aciton使用的自我总结
一.需求: 我需要从后台中获取菜单列表在路由守卫中进行限制. 二.遇到的问题: action中setMenuData的方法如下: actions: { setMenuData(context){ ge ...
- docker自动化启动停止脚本
docker一键启动命令 sh auto.sh [start|restart|stop] [keywords...] keywords可选(包含编号,镜像名,容器名称,端口) 其中defaultLis ...
- python批量将png图片转换为jpg图片
参考引用链接如下:https://www.freesion.com/article/1866518882
- c语言中定义局部变量不赋初值默认
C语言中定义局部变量不赋初值默认为随机数,全局变量定义时候不赋初值默认为0. 但是在keil3中我发现不管全局变量还是局部变量都默认是0.
- data_analysis:初识numpy
import numpy as npimport pandas as pd# """第一种,使用loadtxt"""# # 加载数据路径# ...
- P12证书转BKS证书
安卓 识别的证书格式是bks ,而我之前生成的证书格式是p12 所以需要转换一下,至于怎么生成p12,请看我转载的的文章 Nginx https 双向认证. 1.请先下载第三方转换工具protecl ...
- 4-20mA换算为实际值公式
Ov = [(Osh - Osl) * (Iv - Isl) / (Ish - Isl)] + Osl 实际工程量 = [((实际工程量)的高限 - (实际工程量)的低限)*(lv - 4) / (2 ...
- centos7本地yum配置和使用
1.打开centos的yum文件夹 输入命令cd /etc/yum.repos.d/ 2.用wget下载repo文件 输入命令wget http://mirrors.aliyun.com/repo ...
- MySql密码忘记怎么办?
第一步服务 net stop mysql 第二步,执行指令 mysqld --console --skip-grant-tables --user=mysql --shared-memory 第三步, ...
- 基于Mybatis Plus的一种查询条件构建方案
! 重要: 遐(瞎)想的思路, 希望各位多多建议 record为jdk17写法, 使用class也不会有问题 背景 身为资深程序员, 上班最重要的事当然是增删改查(bushi). 比如今天, 组长甩给 ...