1

I'm using this code to read an excel file and convert it to a JSON Object, but the issue here is that this code read cells that contain date as an integer number

var ExcelToJSON = function () {
this.parseExcel = function (file) {
    var reader = new FileReader();

    reader.onload = function (e) {
        var data = e.target.result;
        var workbook = XLSX.read(data, {
            type: 'binary'
        });
        workbook.SheetNames.forEach(function (sheetName) {
            // Here is your object
            var XL_row_object = XLSX.utils.sheet_to_row_object_array(workbook.Sheets[sheetName]);
            var json_object = JSON.stringify(XL_row_object);

            console.log(JSON.parse(json_object));
            parse(JSON.parse(json_object));
            jQuery('#xlx_json').val(json_object);
        })
    };

    reader.onerror = function (ex) {
        console.log(ex);
    };

    reader.readAsBinaryString(file);
}};

Can anyone help me how to get the date right?

Renan Araújo
  • 3,533
  • 11
  • 39
  • 49
  • what is the value of the int? it might be unix ticks? if so - look here: https://stackoverflow.com/questions/847185/convert-a-unix-timestamp-to-time-in-javascript – developer Apr 07 '20 at 12:18
  • in my excel file i have cell value (4/7/2020) as datetime type but when i read the excel file and convert it to json it comes like this (43928) – user3580800 Apr 07 '20 at 12:22
  • look here - it looks like they use a date serial: https://stackoverflow.com/questions/16229494/converting-excel-date-serial-number-to-date-using-javascript – developer Apr 07 '20 at 12:27
  • thank you that work – user3580800 Apr 07 '20 at 12:34
  • Does this answer your question? [Converting Excel Date Serial Number to Date using Javascript](https://stackoverflow.com/questions/16229494/converting-excel-date-serial-number-to-date-using-javascript) – William A. Apr 07 '20 at 12:56

0 Answers0