Home > Web Front-end > JS Tutorial > body text

Detailed explanation of saving page table content and style into excel file

巴扎黑
Release: 2017-09-14 11:54:56
Original
1528 people have browsed it

在项目做完之余,测试最近做的一个论坛,其中有个导出功能,发现点击网页导出按钮之后,将页面的table内容另存为excel文件后,却发现无法保存表格样式,经过问题分析之后找到根本原因,下面小编就把我的实现思路给大家分享如下:

问题描述:

问题分析过程:

   1.table表格用class,而不是style。导出时并没有导出class定义,若换成style,将颜色样式直接写在style中,就会导出样式。

    style是样式,在HTML中用这个来标明属性样式,是css中的内容,而class是类,申明和定义里面的内容,导出页面时并不会导出定义即class所定义的样式。

  2.将类定义放到table中也可以导出样式

下面通过两种方案解决此问题。

处理方案一:

   将class="${getClass()}"换成style="color:${getStyle()};"

补充:

 $("#export").click(function () {
 saveAsExcel($("h3").text(), $("#table").html().replace(/( )+/gi,""));
 });
Copy after login

其中excel只识别table,使用saveAsExcel方法自动另存时,class定义保存不了;如果手工拷贝粘贴到excel时,class定义就能保存了。

主要还是手工与自动拷贝粘贴问题

处理方案二:

将在<head><style></style></head>中定义的类移动到<table></table>之间即可。类定义样式的位置问题

The above is the detailed content of Detailed explanation of saving page table content and style into excel file. 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
Popular Tutorials
More>
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!