-2

How to read date from an excel file in JavaScript ?

When I fetched a date field from excel file, it comes like some integer/floating point number, how to display the original date present in the excel file.

Rahul Sarma
  • 763
  • 2
  • 8
  • 17
  • How are you running this JavaScript? Are you writing an Excel plugin using JS? Are you reading the file from a JS program external to Excel (e.g. a Node.js program)? What code are you using to fetch the date field? Provide a [mcve] – Quentin Sep 28 '20 at 16:26
  • Fetched external excel file using ReactJs with the help of a get api (NodeJs) – Rahul Sarma Sep 28 '20 at 16:36

1 Answers1

-1

In JavaScript, when we fetch a date field from an excel file, it shows some integer/floating point number. To convert the number back to date, we can use the following:

  1. install excel-date-to-js package (npm i excel-date-to-js)
  2. Run this snippet:
   const { getJsDateFromExcel } = require("excel-date-to-js") 
   getJsDateFromExcel(dateFieldFromExcelFile)   e.g. getJsDateFromExcel(data[1][0])
Rahul Sarma
  • 763
  • 2
  • 8
  • 17
  • That module converts the date format from Excels internal format into a JS date object. It won't preserve the original date format in the spreadsheet. – Quentin Sep 28 '20 at 16:32
  • We'll have to convert it to the format we want, it returns in the timestamp format. – Rahul Sarma Sep 28 '20 at 16:42