-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.

2
  • 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 minimal reproducible example Commented Sep 28, 2020 at 16:26
  • Fetched external excel file using ReactJs with the help of a get api (NodeJs) Commented Sep 28, 2020 at 16:36

1 Answer 1

-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])
Sign up to request clarification or add additional context in comments.

2 Comments

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.
We'll have to convert it to the format we want, it returns in the timestamp format.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.