0

I have been trying to convert html table into csv format by jquery table2csv plugin. Table values are downloading as expected. But only in word format. I can't open it using excel. if i use .csv while downloading data showing in excel. Here is my jquery code

    <script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
    <script type="text/javascript" src="table2CSV.js" > </script>
    <script type="text/javascript">
      $(document).ready(function () {
      $('table').each(function () {
        var $table = $(this);

        var $button = $("<button type='button'>");
        $button.text("Export to spreadsheet");
        $button.insertAfter($table);

        $button.click(function () {
            var csv = $table.table2CSV({
                delivery: 'value'
            });
            window.location.href = 'data:text/csv;charset=UTF-8,'
            + encodeURIComponent(csv);
         });
     });
  })
  </script>
Amir
  • 1
  • Could you post a few lines of the CSV file that you receive? – Paul Jun 12 '14 at 08:36
  • i can't receive csv file until i change the format to .csv . I get word file by default and here it is. "LRP","Farm land","House stead","Pond","Live Stock","Poultry Firm","Others ","Total","Percentage (%)" "LRP-12(YPSA)","3","19",,,,,"22","13.64" – Amir Jun 12 '14 at 08:43
  • You must rename it to ".csv" before excel will read it? That sounds pretty normal, actually. – Paul Jun 12 '14 at 08:45
  • what if i want to change default default extension to .csv ?? – Amir Jun 12 '14 at 08:48
  • If you are using Google Chrome, there's a known bug. See https://code.google.com/p/chromium/issues/detail?id=373182 – Paul Jun 12 '14 at 08:48
  • I make CSV files from JS using code based on [this answer](http://stackoverflow.com/a/17836529/103081), but it doesn't set filename correctly on new Chrome browser any more because of above bug. Firefox and older chrome OK. – Paul Jun 12 '14 at 08:51
  • thanks. I am using both chrome and firefox. It happens in both case. In fact firefox creates anonymous name instead name download. – Amir Jun 12 '14 at 08:56
  • Same thing happening here – Amir Jun 12 '14 at 08:57

0 Answers0