Search code examples
jquerytablesorterexport-to-csv

Tablesorter: Export to CSV and Retain Style


Mottie's Tablesorter output widget is great and working well, but I'm having trouble getting it to respect any HTML applied to the cell. The table is to be imported into Excel via CSV.

  • I have tried traditional tags: <b> inside the cell to bold the text.
  • output_includeHTML is true
  • Various css on the TD itself: style='font-weight: bold; background: green;'

Changing the HTML on the page here: http://mottie.github.io/tablesorter/docs/example-widget-output.html

Didn't return formatted a CSV into Excel, so I'm not sure if it's even built in. I might be requesting more of a hacky way to get tablesorter to respect such styling.


Solution

  • The output widget can export HTML in a csv file

    21,"<span class='red'>John</span>",'Robin'\n\tHood,33,$19.99,25%,"Dec 10, 2002 5:14 AM"
    

    When you load that into Excel, it won't interpret the HTML as anything but text.

    enter image description here

    If you want to retain the color and styling, you can just select the table content, then drag-and-drop the table into Excel (ref)

    enter image description here