Export CSV fieldSeparator bug?

Export CSV fieldSeparator bug?

Tahir wigunaTahir wiguna Posts: 8Questions: 4Answers: 0

I'm trying to make an export CSV button and the separator default is "comma" and I'm trying to change it to semicolon but it broke the CSV. the result when i export it is like this.

but if i change to different symbol or alphabet it works fine, here is my code

function InitDatatableAtt(){

        var buttons = [
            {
                extend: 'csvHtml5',
                text: 'Export CSV',
                fieldBoundary: '',
                fieldSeparator: ';'
            },
        ];

        var table = $('#dttable_att').DataTable({
            "order": [0,"desc"],
            "lengthChange":false,
            "dom": 'Bfrtip',
            "buttons": buttons
        });
}

This question has accepted answers - jump to:

Answers

  • kthorngrenkthorngren Posts: 21,020Questions: 26Answers: 4,893

    Using your code seems to work good in this example:
    http://live.datatables.net/ropavoha/1/edit

    Name;Position;Office;Age;Start date;Salary
    Angelica Ramos;System Architect;London;36;2009/10/09;$2,875
    Ashton Cox;Technical Author;San Francisco;66;2009/01/12;$4,800
    

    Does the CSV file look correct if you open in a text editor instead of a spreadsheet?

    Please provide a test case or update mine to show the issue.

    Kevin

  • Tahir wigunaTahir wiguna Posts: 8Questions: 4Answers: 0
    edited February 2020

    Ummm... not for me here is the result of your code.

    so why it looks like that?
    is there something that i need to setting?

    thanks for replying me :)

  • Tahir wigunaTahir wiguna Posts: 8Questions: 4Answers: 0

    oops sorry i dont see your question,
    yes it is fine on text editor but my client want to open it on excel

  • kthorngrenkthorngren Posts: 21,020Questions: 26Answers: 4,893
    Answer ✓

    A CSV file is a text file not a spreadsheet file. Open the file in a text editor to view it. Are you wanting to open the file in a spreadsheet or something else?

    Kevin

  • Tahir wigunaTahir wiguna Posts: 8Questions: 4Answers: 0

    Wow! thanks for the info bro :smile:. but it is possible to open it in spreadsheet?

  • kthorngrenkthorngren Posts: 21,020Questions: 26Answers: 4,893
    Answer ✓

    Is Excel the spreedsheet you are using? If so change the button type to Excel. You will also need to have JSZip.js which you can get from the Download Builder.

    Kevin

  • Tahir wigunaTahir wiguna Posts: 8Questions: 4Answers: 0

    Wow, it works! Thanks man <3

  • allanallan Posts: 62,906Questions: 1Answers: 10,350 Site admin

    Do you mean the ####### in place of a date? Excel will show that if it doesn't have space to render a date field. You could make the column wider in Excel. Or as Kevin says, use the Excel export which does automatic column width adjustment in the created file (not possible in a plain CSV file).

    Allan

This discussion has been closed.