Export to excel or csv with Greek Letter

Export to excel or csv with Greek Letter

sarooptrivedisarooptrivedi Posts: 45Questions: 15Answers: 2
edited February 2022 in Buttons

I have special Greek letter in my table header.

<th>Total Eff α</th>

in csv export alpha and beta replace with garbage value with Total Eff α

How to render the special greek character in header

you can find the HTML entity for the greek letter alpha on below link

javascripter.net/faq/greekletters.htm

HTML code for alpha
https://w3schools.com/charsets/tryit.asp?deci=945&ent=alpha

My Jquery Code

      {
                    extend: 'csv',
                    titleAttr: 'csv',
                    autoFilter: true,
                    sheetName: 'Exported data',
                    exportOptions: {
                        columns: ':visible',
                        charset: 'UTF-8',
                        format: {

                            header: function (data, row, column, node) {
                                if (data == "Total α") {

                                    return data.replace("α","&#945;");

                                }

                            }
                        }
                    }
                },

This question has an accepted answers - jump to answer

Answers

  • sarooptrivedisarooptrivedi Posts: 45Questions: 15Answers: 2

    I found the issue as well.

    In Buttons.html5.js lines 968 to 972 line
    _saveAs(
    new Blob( [output], {type: 'text/csv'+charset} ),
    info.filename,
    true
    );

  • allanallan Posts: 61,635Questions: 1Answers: 10,092 Site admin
    Answer ✓

    Hi,

    I'm not entirely clear on what the issue with the code there is (i.e. how did you identify that as the problem)? I'm wondering if it would work if you had charset: '; charset=UTF-8'?

    Allan

  • sarooptrivedisarooptrivedi Posts: 45Questions: 15Answers: 2

    I tried this and its worked

      {
                    extend: 'csv',
                    titleAttr: 'csv',
                    autoFilter: true,
                    sheetName: 'Exported data',
                    charset: 'utf-8',
                    bom: true,
                    exportOptions: {
                        columns: ':visible',
                    }
    
                },
    
  • allanallan Posts: 61,635Questions: 1Answers: 10,092 Site admin

    The bom option is what made the difference? Surprising! What text editor are you using?

    Allan

  • rf1234rf1234 Posts: 2,802Questions: 85Answers: 406

    Guys, I can confirm that. I don't have Greek but special German letters such as ä ö ü Ä Ö Ü ß.

    For the CSV export I use this. I definitely needed the "bom" option to make it work. (The value of the field separator and the filename depend on the user language.)

    //custom button for cashflow csv generation
    $.fn.dataTable.ext.buttons.csvCashFlow = {
        extend: 'csv', fieldSeparator: csvSep, 
                       charset: 'UTF-8', bom: true,
                       filename: cashFlowTitle,
    ....
    
  • allanallan Posts: 61,635Questions: 1Answers: 10,092 Site admin

    How interesting! I used to have the BOM option enabled by default, but got lots of complaints because some editors actually tried to render it rather than correctly seeing it as a BOM. The whole BOM handling is just a mess!

    I tend to use VSCode and it picks up text files as UTF-8 by default for me (with or without a BOM).

    Allan

  • sarooptrivedisarooptrivedi Posts: 45Questions: 15Answers: 2

    I am using Visual studio 2022

  • rf1234rf1234 Posts: 2,802Questions: 85Answers: 406

    My users are opening those csv files with MS Excel. For that to work the BOM option was required.

Sign In or Register to comment.