0

I'm creating a webpage where i have an option to expert data as an excel file. The data is saved in my native language, so it has š, ž, ā, ī, ū e.t.c. But when i export it Metāla šķēres 20cm turns into MetÄla šķēres 20cm

Heres my javascript.

<script type="text/javascript">

function exportData(){

    var table = document.getElementById("data");
    var rows =[];

    column1 = "";
    column2 = "";
    column3 = "";
    column4 = "";
    column5 = "";
    column6 = "";
    column7 = "";

    rows.push(
        [
            column1,
            column2,
            column3,
            column4,
            column5,
            column6,
            column7
        ]
    );


    for(var i=0,row; row = table.rows[i];i++){
        column1 = row.cells[0].innerText;
        column2 = row.cells[1].innerText;
        column3 = row.cells[2].innerText;
        column4 = row.cells[3].innerText;
        column5 = row.cells[4].innerText;
        column6 = row.cells[5].innerText;
        column7 = row.cells[6].innerText;

        rows.push(
            [
                column1,
                column2,
                column3,
                column4,
                column5,
                column6,
                column7

            ]
        );

        }
        csvContent = "data:text/csv;charset=utf-8,";

        rows.forEach(function(rowArray){
            row = rowArray.join(";");
            csvContent += row + "\r\n";
        });

        var encodedUri = encodeURI(csvContent);
        var link = document.createElement("a");
        link.setAttribute("href", encodedUri);
        link.setAttribute("download", "Inventory_Report.csv");
        document.body.appendChild(link);

        link.click();
}
</script>

I have tried to find something similar, but nothing i found works for me.

Any suggestion would be appreciated!

P.s if you need more information, let me know.

Thank you!

  • It didnt at first, hence i asked the question, but looking over it again i realized where i made my mistake. No idea why it was a mistake tho, but it works now. – emils veveris Jan 12 '22 at 09:04

0 Answers0