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( ...
随机推荐
- PHP 网页 apache24+php8 yii basic
PHP官网下载 https://windows.php.net/download/ 在PHP官网点击Download下载时不管选择哪个版本的都有两个类型 : Non Thread Safe(非线程安全 ...
- mysql 备份定时任务
#!/bin/bash rq=`date +%Y-%m-%d-%H` #日期 #数据库信息 host=127.0.0.1 user=root password=xxx dbname=script #放 ...
- Kubernetes部署的10个注意事项
摘要 容器开发有望在云中实现前所未有的可移植性和可扩展 性.此外,DevOps 开发和文化实践也有助于提升业务价 值和响应能力.但是,在开始第一个容器开发项目之前, 有一些问题需要考虑清楚:我们应该使 ...
- C# 海康威视网络半球摄像头回调YV12取画面
海康网络摄像头回调取画面,网口最好用千兆的网卡来做,开始用笔记本的百兆网口,不管怎么优化都是卡顿的, 后来用千兆网卡台式机的,基本就没有卡顿了,取图再加上运动检测处理,基本上十几毫秒每帧. 用回调方式 ...
- c# Winform 缓动动画
一.定义缓动动画类public class AnimationHelper { Timer animationTimer = new Timer(); double velocity = 0.0; P ...
- MassTransit - .NET Core 的分布式应用程序框架
简介 MassTransit 是一个免费的.开源的.NET 分布式应用程序框架.MassTransit 使创建应用程序和服务变得容易,这些应用程序和服务利用基于消息的松散耦合异步通信来实现更高的可用性 ...
- 使用 WSDL 指定的标准 SOAP 消息格式
为 XML 文档(定义 Web 服务)定义架构的行业标准 Web 服务描述语言 (WSDL) 提供了两个主要的 SOAP 格式设置选项.这两个选项均在 XML 元素中指定,而不在主 WSDL 命名空间 ...
- python+接口参数化(ddt和pytest.mark.parametrize())使用
一.ddt(基于unittest) 实例:字典解包[{},{}] test_data=t.read_excel(mode,case_list)@ddt class Interface(unittest ...
- gopher必读文章
Getting Started with Go Programminghttps://www.programiz.com/golang/getting-startedHow to Write Go C ...
- 算法学习—————PAM回文自动机
时隔一年,第一次学习新的算法 原理和AC自动机差不多 基本思想: 两棵树分别代表奇偶 在一个回文串两边同时填上相同字符可以得到另一个回文串,以此构建两棵树 树上维护信息: 节点表示的回文串为当前位置的 ...