How to save page table contents and styles as Excel files _javascript tips

Source: Internet
Author: User
Tags class definition

In the end of the project, the test recently done a forum, which has an export function, found that click on the page Export button, the page table content saved as an Excel file, but found that can not save the table style, after the problem analysis to find the root cause, The following small series on my realization of the idea to share as follows:

Problem Description:

Problem Analysis Process:

The 1.table table is in class, not style. The class definition is not exported, and if you change to style, the style is exported by writing the color style directly in the style.

Style is a style that is used in HTML to indicate the attribute style, is the content in the CSS, and class is the class, declares and defines the contents of the content, export the page does not export the definition that is defined as class style.

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

The following two scenarios are used to resolve this problem.

Treatment Scheme I:

Replace the class= "${getclass ()}" with Style= "Color:${getstyle ()};"

Add:

 $ (' #export '). Click (function () {
 saveasexcel ($ (' H3 '). Text (), $ (' #table '). html (). Replace (/() +/gi, ');
 });

Where Excel recognizes only the table, the class definition is not saved when the Saveasexcel method is used automatically, and the class definition is saved if the manual copy is pasted into Excel.
Mainly manual and automatic copy pasting problem

Treatment Programme II:

Move the class defined in

The above content is the whole content of this article, Hope everybody likes.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.