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
WBOYOriginal
2016-05-16 15:46:571611browse

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,''));
 });

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 93f0f5c25f18dab9d176bd4f6de5d30ec9ccee2e6ea535a969eb3f532ad9fe89531ac245ce3e4fe3d50054a55f2659279c3bca370b5104690d9ef395f2c5f8d1 to f5d188ed2c074f8b944552db028f98a1f16b1740fad44fb09bfe928bcc527e08. Position issue of class definition style

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

Statement:
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