I
I
Idobrodushniy2017-11-17 13:13:27
JavaScript
Idobrodushniy, 2017-11-17 13:13:27

How to export html to excel with js(UTF-8 REQUIRED)?

There is this code

var data_type = 'data:application/vnd.ms-excel/charset=UTF-8';
        var tables_divs_sum_html = '<table border=1 ><tbody ><tr border=1  ><td border=1 >';
        var table_divs = document.getElementsByClassName('calculate--container')
        for(let i=0;i<table_divs.length;i++){
            if(i === table_divs.length - 1){
                tables_divs_sum_html += table_divs[i].outerHTML+'</td></tr></tbody></table>';
            } else {
                tables_divs_sum_html += table_divs[i].outerHTML+'</td><td>';
            }
        }
        var table_html = tables_divs_sum_html.replace(/ /g, '%20');
        var a = document.createElement('a');
        a.href = data_type + ', ' + table_html
        a.download = `Report_for_${this.props.match.params.month}_${this.props.match.params.year}`+'.xls';
        a.click();

The problem is that I need to export to excel exactly so that the encoding is UTF-8. But for some reason this approach does not work. Please advise with a solution. Thank you.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question