I ask help here about a trouble with SheetJS js-xlsx that recently seems not to be supported actively. I already put an issue.

The point is that I want to use non-English data format (dates and numbers). When I export to XLSX file, the library does not process correctly and the represented information in the exported Excel is wrong.

2 Answers

Selkie On

I don't have all the information, so I'm taking a blind stab in the dark x2:

1) If the date is being returned as a string, you can try and parse it out using things like left, right, mid, len, etc., then re-arrange it using the Date function.

2) It's possible to change the base language of Excel, which has the effect of changing the date format being used. You can change to a version of Excel where things work, process there, then convert back to the original language, which will convert the file over.

Again, with a lack of information, and a lack of the business need for doing this, I can't give a better response

Shahar Hadas On

My solution would be different.

Build the custom excel format in code. Attached is an example, which I think you should be able to improve upon.

This is a simple rewrite of your exportToXls function:

    function exportToXls() {
        var wb = XLSX.utils.book_new();
        var ws = XLSX.utils.json_to_sheet(vm.list, {header: ["date", "number"], cellDates: true});

        // Headers

        // Data
        for(var i = 0; i < vm.list.length; ++i) {
            ws[`A${i+2}`].z = 'd/m/yy';
        XLSX.utils.book_append_sheet(wb, ws, 'Somename');
        XLSX.writeFile( wb, 'Table.xlsx' );

$$hashkey is due to Angular (uses it to scan for changes). If you'll use a separate method or variable to inject the data, as shown in the example below, the $$hashkey will not be present.

Here it is in action Codepen.