I need to unload some spreadsheet in Excel. For this, I use the following code:

var excel = function(table, worksheetName) { var uri = 'data:application/vnd.ms-excel;base64,'; var template = '<html\ xmlns:o="urn:schemas-microsoft-com:office:office"\ xmlns:x="urn:schemas-microsoft-com:office:excel"\ xmlns="http://www.w3.org/TR/REC-html40">\ <head>\ <!--[if gte mso 9]>\ <xml>\ <x:ExcelWorkbook>\ <x:ExcelWorksheets>\ <x:ExcelWorksheet>\ <x:Name>{worksheet}</x:Name>\ <x:WorksheetOptions>\ <x:DisplayGridlines/>\ </x:WorksheetOptions>\ </x:ExcelWorksheet>\ </x:ExcelWorksheets>\ </x:ExcelWorkbook>\ </xml>\ <![endif]-->\ </head>\ <body>\ <table>\ {table}\ </table>\ </body>\ </html>'; var base64 = function(s) { return $window.btoa(unescape(encodeURIComponent(s))); }; var format = function(s,c) { return s.replace(/{(\w+)}/g, function(m,p){ return c[p]; }); }; var ctx = { worksheet: worksheetName, table: table.innerHTML }; var href = uri + base64(format(template, ctx)); return href; } 

If it matters, here is the original code: https://codepen.io/marco27384/pen/pboLyx

The problem is: the Russian text is displayed like this:

% u0421% u0438% u0431% u0438% u0440% u0441% u043A% u% 438% u0435% 20% u043F% u0435% u043B% u044C% u043C% u0435% u043D% u0438% 0A% 0A% u0412% 201979 % u044F% 20% u0437% u0430% u043A% u0430% u043D% u0447% u0438% u0432% u0430% u044E% 20% u0438% u043D% u0441% u0442% u0438% u0442% u0443% u0442% u0442% u0442% u0442% u0442% u0442% u0442% u0442%% u044% % u0440% u0430% u0441% u043F% u0440% u0435% u0434% u0435%

How to fix it?

    1 answer 1

    The problem was terribly simple. I experimented with uploading to Excel and at one time I had a function encode , which I processed the text before uploading.

    Later, I deleted the encode function, but still tried to use it:

     ... encode(text) ... 

    It is because of this that the text turned into cracks.