saving to xls

saving to xls

whiterabbitwhiterabbit Posts: 5Questions: 0Answers: 0
edited February 2011 in TableTools
Hi,
this tabletools is great!

i have a question about the excel export: the filename can be set in the javascript and this filename then appears in the flash file save dialogue. however if the user changes the filename in the dialogue but doesnt put the .xls at the end then it will be saved with no extension. since the typical end user doesnt know about file extensions, is there a way that the extension can automatically be added to the end of the filename after it has been changed in the dialogue. would this be a change to the flash?

thanks

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    This is indeed a Flash thing - and unfortunately Flash doesn't appear to allow the control you are looking for: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/FileReference.html . The 'extension' property is readonly - so for file upload. Unfortunately I don't see how it can be set like in a typical Windows file save dialogue... Possibly need a feature request against Flash.

    Allan
  • kennethkenneth Posts: 2Questions: 0Answers: 0
    Hi,

    Is there anyway of fixing this bug manually in code?
    something like this in pseudo code:
    [code]
    if(fileName.hasNoExtension) {
    fileName + ".csv";
    }
    [/code]

    thanks
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Its not a bug as such since it is a feature of flash, but you can certainly specify the full name of the file, but how would it know to open with Excel if you don't give it the extension, since there is no MIME type?

    Allan
  • kennethkenneth Posts: 2Questions: 0Answers: 0
    I found out how i can change the name for the file, but as Whiterabbit said:
    [quote]whiterabbit said: however if the user changes the filename in the dialogue but doesnt put the .xls at the end then it will be saved with no extension.[/quote]
    And there isn't a solution for this problem?
  • heyvaersheyvaers Posts: 4Questions: 0Answers: 0
    To solve this, the swf needs to be changed to check whether an extension is given or not with the filename.
    When the dialog pops up, the filename is easily overwritten, because it is selected.
    I don't think Flash is responsible for this behaviour. I see it as a shortcoming in the .swf code.
    The code is not "monkey-proof" at this time, and needs to be to be appropiate for different kinds of end-users.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    [quote]heyvaers said: the filename is easily overwritten, because it is selected.

    I don't think Flash is responsible for this behaviour[/quote]

    I don't see any options in the FileReference documentation which allows this behaviour to be altered. If anyone with better eyes than me can see what is needed, the input would be very welcome! http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/FileReference.html?filter_flash=cs5&filter_flashplayer=10.2&filter_air=2.6

    Allan
  • heyvaersheyvaers Posts: 4Questions: 0Answers: 0
    I actually meant you should check this in the copy_cvs_xls.swf code, in the clickHandler code. Just before you do a save(), the filename can be checked for the presence an extension.
    I presume the copy_cvs_xls.swf is written by you?
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    The source for copy_cvs_xls.swf (which is indeed part of the TableTools sub-project) is available here: https://github.com/DataTables/TableTools/blob/master/media/as3/ZeroClipboardPdf.as#L152 - that's the line which does the actual save. It appears that you can sent the full file name and only the full file name (including the extension), but you can't say what the extension should be (unless I'm missing something). So while I could enforce that the developer has an extension on the file, I don't see how I can enforce that the user leaves it there.

    Allan
  • heyvaersheyvaers Posts: 4Questions: 0Answers: 0
    edited August 2011
    Ok, it seems like a flash issue indeed:
    http://bugs.adobe.com/jira/browse/FP-2014
    http://bugs.adobe.com/jira/browse/FP-5654
    ...
    But still, I think you should implement a workaround (e.g. add a property with a default extension to use when the file has no given extension).
    Or at least give a warning about the file not having an extension (=worst solution).
    Since the bug is not new, a lot of users will have the problem.
  • whiterabbitwhiterabbit Posts: 5Questions: 0Answers: 0
    Allan does the following from your link above run after the save dialogue has appeared and the user has pressed save:

    fileRef.save (.....

    or is that what makes the file dialogue appear?

    was thinking if it runs afterwards the filename could be checked and if there is no extension one can be added eg all excel would be xls, csv would be csv, pdf would be pdf etc
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    @heyvaers: I don't understand how I would know that the file has been saved without an extension? All I can currently do is open the save dialogue box with the name of the file (including the extension). If the user then wants to change or remove the extension, I can't stop that, nor do I know that it has happened. If the developer tells TableTools to save a file without an extension than that's a choice on the developers part (but again, the user can add one if they want). I don't see any way around that.

    @whiterabbit: The .save() method is what makes the dialogue box appear with the file name that you want given to it (but again the user can override that if they want).

    Allan
  • heyvaersheyvaers Posts: 4Questions: 0Answers: 0
    I don't want to question everything, but whence comes the choice of ActionScript?
    Datatables itself is all written in javascript. Is it because of the support to pdf output?
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    No, its because of the need to write a file to the local file system in a cross browser manner. Flash 10 added that ability and with the ability to communicate between Javascript and Flash it seemed ideal to use when there is no way to do it using just Javascript (at least not with all browsers - that is changing with the new APIs though).

    Allan
  • mstmariemstmarie Posts: 1Questions: 0Answers: 0
    I started at this spot here (TableTools.min.js):
    xls:{sAction:"flash_save",sCharSet:"utf16le",bBomInc:true,sFileName:"*.csv"

    and changed it to:
    xls:{sAction:"flash_save",sCharSet:"utf16le",bBomInc:true,sFileName:"*.xls"

    Now, when the dialog pops up, the filename has the .xls extension. You're still going to get an error message when opening it in Excel, and that is simply due to the fact of its encoding.
This discussion has been closed.