Convert HTML to Excel and realize printing and downloading functions

jacklove
Release: 2018-06-11 23:42:16
Original
2404 people have browsed it

   
超链接_导出表格
" + document.getElementById("print-content").outerHTML + ""; // 实例化一个Blob对象,其构造函数的第一个参数是包含文件内容的数组,第二个参数是包含文件类型属性的对象 var blob = new Blob([html], { type: "application/vnd.ms-excel" }); var a = document.getElementById("print-click"); // 利用URL.createObjectURL()方法为a元素生成blob URL a.href = URL.createObjectURL(blob); // 设置文件名,目前只有Chrome和FireFox支持此属性 a.download = "会签单.xls"; function download() { debugger // 使用outerHTML属性获取整个table元素的HTML代码(包括标签),然后包装成一个完整的HTML文档,设置charset为urf-8以防止中文乱码 var html2 = "
" + document.getElementById("print-content").outerHTML + ""; // 实例化一个Blob对象,其构造函数的第一个参数是包含文件内容的数组,第二个参数是包含文件类型属性的对象 var blob2 = new Blob([html2], { type: "application/vnd.ms-excel" }); saveAs(blob2, "应系单.xls"); }; //打印具体实现代码 function printout() { debugger; var newWindow; //打开一个新的窗口 newWindow = window.open(); // 是新窗口获得焦点 newWindow.focus(); //保存写入内容 var newContent = "打印
" newContent += document.getElementById("print-content").outerHTML; newContent += "" // 将HTML代码写入新窗口中 newWindow.document.write(newContent); newWindow.print(); // close layout stream newWindow.document.close(); //关闭打开的临时窗口 newWindow.close(); return false; };
Copy after login

This article explains how to convert HTML to Excel and implement printing and downloading functions. For more related content, please pay attention to the php Chinese website.

Related recommendations:

Simple PHP MySQL paging class

Three methods for php to generate QR codes

Two tree array constructors without recursion

The above is the detailed content of Convert HTML to Excel and realize printing and downloading functions. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!