<转>HTML中的table转为excel
2013-10-14 19:26
399 查看
转换html 中的table 为excel,firefox浏览器支持,代码如下
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> <script type="text/javascript"> 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> </head> <body> <h1>tableToExcel Demo</h1> <p>Exporting the W3C Example Table</p> <input type="button" onclick="tableToExcel('testTable', 'W3C Example Table')" value="Export to Excel"> <h4>两行三列:</h4> <table id = 'testTable' border="1"> <tr> <td>100</td> <td>200</td> <td>300</td> </tr> <tr> <td>400</td> <td>500</td> <td>600</td> </tr> </table> </body> </html>
相关文章推荐
- HTML中的table转为excel
- <学习html>第五天笔记-表格table(创建表格、表格属性、表头标签、表格结构、表格标题标签、合并单元格)
- HTML中的<table>标签及其子元素标签,JS中DOM对<table>的操作
- html导出table支持(excel,png,word,pdf<pdf不太行,中文不支持>)
- HTML中的<select>标签如何设置默认选中的选项
- 使用正则表达式匹配HTML 下各种<title>标签
- HTML中的<UL>标签中li横向排列
- javscript 导出html中的table到excel
- 在JS里面,取struts的<html:form>标签里面的<html:text property="title"/>值
- HTML基础___CSS样式表__上 <第九天>
- js导出HTML的Table到Excel中
- ASP.NET4.0新的<%: %>语法用于HTML Encoding
- IIS7中添加html对<! #include >的引用
- html中table导出Excel
- <!DOCTYPE html PUBLIC……>的组成解释
- pb9中使用htmltable方式将数据窗口导出为excel文件的几点看法
- 用html中的<base>来控制网页的基准页面
- 将html中table导出到excel xls文件的一种可用方法
- placeholder 属性 <input>标签 HTML 5特有属性
- HTML <table> 标签