Output to Excel as .xls (not .xlsx or .csv)

Output to Excel as .xls (not .xlsx or .csv)

raw10raw10 Posts: 2Questions: 0Answers: 0
edited May 2013 in TableTools
Hi Allan,

I've been playing around with exporting to Excel, and TableTools + DataTables works well for exporting to .csv files. The issue as you know is exporting to a formatted Excel file, and I've read a number of discussions here and elsewhere about the idea and problems of generating .xls and .xlsx from the browser.

Have you considered simply exporting the table as an HTML document with the .xls extension? Excel will accept it gracefully and attempt to preserve formatting, formulas, merged cells, and so on. It's not as elegant as writing the native XML and zipping it up into .xlsx directly, but I think it might be a simple workaround that's better than the current .csv-only solution.

Replies

  • allanallan Posts: 63,204Questions: 1Answers: 10,415 Site admin
    That's not something I'd considered actually - I hadn't realised that Excel can read HTML tables.

    I've opened an issue for TableTools to cover this: https://github.com/DataTables/TableTools/issues/25 . I'm not sure when I'll get a chance to do it as all of my available effort is currently being put into v1.10 (and the forum of course :-) ), but it sounds like a good idea. Thanks for suggesting it!

    Allan
  • raw10raw10 Posts: 2Questions: 0Answers: 0
    Great! One thing to note is that Excel does expect the file to be a full HTML page. In my testing the minimum requirement would be to wrap the table in and tags. It won't recognize the file without those.
  • liwu198923liwu198923 Posts: 0Questions: 0Answers: 0
    为什么使用tableTools swf路径正确按钮还是无效
  • ChaosChaos Posts: 1Questions: 0Answers: 0
    I'm also one of the guys waiting for a solution on the XLS export method.
    I just found this: http://stackoverflow.com/questions/14125819/export-html-table-to-excel-but-select-a-name-for-the-file

    Would this be a viable solution?
  • allanallan Posts: 63,204Questions: 1Answers: 10,415 Site admin
    Possibly. Doesn't work with old IE, and as noted in the comments, you can't really specify a download file name. So a bit too limited for inclusion in TableTools core.

    Allan
This discussion has been closed.