Export to Excel - wrong extention (.csv).

Export to Excel - wrong extention (.csv).

CorranCorran Posts: 10Questions: 0Answers: 0
edited February 2011 in TableTools
The new TableTools 2.0 is great but I discovered a strange bug.

When you select Export to Excel (even in the example on this very site: http://www.datatables.net/release-datatables/extras/TableTools/index.html) the filename given ends with .csv (in the above case it's TableTools example.csv).

Renaming it manually to .xls works fine but this will be beyond the skillset of many people unfortunately.

The downloaded file is different from the CSV option though, the file size and content are not the same.

Replies

  • max4evermax4ever Posts: 45Questions: 0Answers: 0
    if you look in tabletools.js (the uncompressed version)
    there is this part
    [code]
    "xls": {
    "sAction": "flash_save",
    "sCharSet": "utf16le",
    "bBomInc": true,
    "sFileName": "*.csv",
    "sFieldBoundary": "",
    "sFieldSeperator": "\t",
    "sNewLine": "auto",
    "sTitle": "",
    "sToolTip": "",
    "sButtonClass": "DTTT_button_xls",
    "sButtonClassHover": "DTTT_button_xls_hover",
    "sButtonText": "Excel",
    "mColumns": "all",
    "bHeader": true,
    "bFooter": true,
    "fnMouseover": null,
    "fnMouseout": null,
    "fnClick": function( nButton, oConfig, flash ) {
    this.fnSetText( flash, this.fnGetTableData(oConfig) );
    },
    "fnSelect": null,
    "fnComplete": null,
    "fnInit": null
    },
    ...
    [/code]

    so basically you can do it like this (i tried and it works)
    [code]
    "oTableTools": {
    "sSwfPath": "/flash/copy_cvs_xls_pdf.swf",
    "aButtons": [
    {
    "sExtends": "xls",
    "sButtonText": "<?php echo $this->translate('xls tabella')?>",
    "sFileName": "*.xls"
    },
    ....
    [/code]

    that is you use "sFileName": "*.xls"
  • GregPGregP Posts: 487Questions: 8Answers: 0
    Are the two files not actually the same? I was wondering about this myself. It seems to me that the "Excel" sheet is just a CSV, which Excel can also read. The main benefit of changing the extension would be for the user's machine to open the proper helper application (Excel); but for Excel users, it's also usually the default for CSV.

    I'm currently disabling export to "excel" and letting Excel users just open the CSV. But if there's an actual format difference between the two, I might re-enable it and use the above suggestion.
  • allanallan Posts: 54,882Questions: 1Answers: 8,601 Site admin
    edited February 2011
    Greg is exactly right here - the Excel export is a little bit of a cheat since it's really outputting a CSV file (with UTF-16LE BO), which Excel will open no problem (and open by default on most systems). It's perfectly possible to use the .xls extension instead, however some versions of Excel will give a warning saying that the file is not in xls format (which it isn't - so fair enough). There was some concern that end users didn't like this (which I agree with), so I chose to use the .csv extension, which should have as small as possible impact on the end user (particularly non-technical ones).

    It is perfectly possible to write xls files, I just need to get the time to read, understand and reproduce the format - it is on the to-do list :-)

    Regards,
    Allan
  • talkitivewizardtalkitivewizard Posts: 30Questions: 0Answers: 0
    edited March 2011
    If you want to do the 2007/2010 format, it would be VERY simple seeing as it is just xml. I've done lots of work with powerpoints and have gotten to look at the file formats for all office documents. Maybe I can give you a hand on this part at some point. I'll just have to sit down and learn your framework for saving files from JS using flash.
    From one Allan to another Allan :P

    Allan Chappell
  • allanallan Posts: 54,882Questions: 1Answers: 8,601 Site admin
    Aren't the xlsx files zip compressed in a certain directory structure? Or is it just an uncompressed XML stream? I don't actually have Office available at the moment, so perhaps someone might be able to send me a XML file which Excel can open so I can reproduce the format?

    Allan
  • talkitivewizardtalkitivewizard Posts: 30Questions: 0Answers: 0
    your first assumption is actually correct. There's alot to the SpreadsheetML. Here's alink to the reference http://dl.dropbox.com/u/7177934/Ebooks/2427191-Office-Open-XML-Part-4-Markup-Language-Reference.pdf.
    Also a quick more picture filled guide
    http://dl.dropbox.com/u/7177934/Ebooks/Open%2BXML%2BExplained.pdf

    and lastly, an xlsx file that you can have fun with... just use winrar, or your favorite archive utility to unzip it... it's just a standard zip.
    http://dl.dropbox.com/u/7177934/tracking_report_476.xlsx

    I hope this helps
  • allanallan Posts: 54,882Questions: 1Answers: 8,601 Site admin
    Cool thanks very much! It looks like that although Flash has built in ZIP compression for ByteArrays it doesn't do directory structures - so I'll probably need an external library for that kind of thing. Its not going to be trivial I suspect, since it looks like more than just creating an XML file, which would be dead easy... So it goes :-)

    Allan
  • talkitivewizardtalkitivewizard Posts: 30Questions: 0Answers: 0
    edited March 2011
    Sorry about miss leading you in anyway. I'm used to using PHP or C# to perform tasks. JS is not my strongest of languages, however, it has prepared me and spoiled me to the functionality that finally came out in PHP5.3 with anonymous functions and closures. (not that php5.3 has closures really but JS does! :D)

    Good luck, and you're welcome. Thank you for providing such a cool product. Many a site would be bland and less user friendly if it wasn't for you.
This discussion has been closed.