Save the content and style of the table on the page into an excel file, tableexcel
After the project is completed, test a recently created forum with an export function. After you click Export on the webpage, save the table content on the page as an excel file, however, the table style cannot be saved. After analyzing the problem, find the root cause. The following section will share my Implementation ideas with you as follows:
Problem description:
Problem analysis process:
1. Use a class instead of a style in a table. The class definition is not exported during export. If you change to style, you can write the Color style directly in the style to export the style.
Style is a style. This is used in HTML to indicate the attribute style. It is the content in css, while class is the content in class, declaration and definition, the style defined by class is not exported when the page is exported.
2. Place the class definition in the table and export the style.
The following two solutions are provided to solve this problem.
Solution 1:
Change class = "$ {getClass ()}" to style = "color :$ {getStyle ()};"
Supplement:
$('#export').click(function () { saveAsExcel($('h3').text(), $('#table').html().replace(/( )+/gi,'')); });
Excel only recognizes tables. When the saveAsExcel method is used for automatic saving, the class definition cannot be saved. If you copy and paste it to excel manually, the class definition can be saved.
It is mainly about manual and automatic copy and paste.
Solution 2:
Move the class defined in
The above content is all the content of this article. I hope you will like it.