Home > Web Front-end > JS Tutorial > How to save page table content and style into excel file_javascript skills

How to save page table content and style into excel file_javascript skills

WBOY
Release: 2016-05-16 15:46:57
Original
1590 people have browsed it

After finishing the project, I tested a recently created forum, which has an export function. I found that after clicking the web page export button and saving the table content of the page as an excel file, I found that the table style could not be saved. After the problem After analysis, I found the root cause. Now I will share with you my implementation ideas as follows:

Problem description:

Problem analysis process:

1. Table uses class instead of style. The class definition is not exported when exporting. If you change to style and write the color style directly in style, the style will be exported.

Style is the style, which is used in HTML to indicate the attribute style, which is the content in css, and class is the class, which declares and defines the content. When exporting the page, the definition, that is, the style defined by class, will not be exported.

2. You can also export styles by placing the class definition in the table

There are two solutions to solve this problem.

Solution 1:

Replace class="${getClass()}" with style="color:${getStyle()};"

Supplement:

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

Excel only recognizes tables. When you use the saveAsExcel method to automatically save, the class definition cannot be saved; if you manually copy and paste it into excel, the class definition can be saved.
The main problem is manual and automatic copy and paste

Solution 2:

Just move the classes defined in to

. Position issue of class definition style

The above is the entire content of this article, I hope you all like it.

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