Exporting from Excel is causing dates and times to be displayed as numbers instead

Having trouble with a specific date while exporting an Excel file. Refer to the screenshot of the Excel file for clarity: https://i.stack.imgur.com/7mFE4.png

The date '01/02/2019 00:00:00' is being treated as a number instead of displaying correctly like all other dates. Below is the code snippet:

fireEvent() {
        const ws: XLSX.WorkSheet = XLSX.utils.table_to_sheet(this.table.nativeElement);
        const wb: XLSX.WorkBook = XLSX.utils.book_new();
        XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');
        XLSX.writeFile(wb, 'ExportDatiTable.xlsx');
    }

If you have any suggestions on how to resolve this issue, please let me know. Thank you.

Answer №1

let worksheet: XLSX.WorkSheet = XLSX.utils.table_to_sheet(this.table.nativeElement, 
         {dateNF:'dd/mm/yyyy;@', cellDates:true, raw: true});
        let workbook: XLSX.WorkBook = XLSX.utils.book_new();
        XLSX.utils.book_append_sheet(workbook, worksheet, 'DataSheet');
        XLSX.writeFile(workbook, 'ExportedData.xlsx');

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Guidance on incorporating a function as a prop in React using TypeScript

I'm currently learning TypeScript with React and ran into an issue. I attempted to pass a function as a property from my App component to a child component named DataForm. However, I encountered the following error: Type '(f: any) => any&ap ...

The Facebook share button is functioning properly, however, when attempting to post a message, an error

Currently, I am utilizing the ngx-sharebuttons library for Angular 8 and everything seems to be working properly with the buttons. However, when attempting to share a link, the post message displays my website's URL along with an error message. It&apo ...

Issue ( Uncaught TypeError: Trying to access a property of undefined ('data') even though it has been properly defined

One of my custom hooks, useFetch, is designed to handle API data and return it as a state. useFetch: import { useState, useEffect } from "react"; import { fetchDataFromApi } from "./api"; const useFetch = (endpoint) => { const [d ...

Typescript libraries built specifically for unique custom classes

I am currently exploring the most effective method for creating a class library in Typescript and deploying it to NPM along with a definitions file. The classes within the library serve as models that are utilized by multiple RESTful services. Some of the ...

Ways to show a div when a dropdown option is selected

Currently, I am in the process of designing a form that includes a dropdown menu. Once the user selects a particular option from the list, such as: Software developer a new section will be displayed, showing two additional options: App Developer ...

What is the correct way to properly cancel a request?

Imagine a scenario where I am utilizing a service that sends HTTP requests to my API and returns observables, which is pretty common. While using this service, the user might become impatient and decide to cancel the request by calling my-subscription.uns ...

Introduce a specialized hierarchical data structure known as a nested Record type, which progressively ref

In my system, the permissions are defined as an array of strings: const stringVals = [ 'create:user', 'update:user', 'delete:user', 'create:document', 'update:document', 'delete:document&ap ...

How can I define types for (const item of entries) in Typescript?

I attempted for (const ElementType as element of elements ) {} or for (const ElementType of elements as element) {} However, neither of these options is correct. ...

Is there a way to make Typescript accept dot notation?

Is there a way to suppress the compile time error in Typescript when using dot notation to access a property that the compiler doesn't know about? Even though using bracket notation works, dot notation would be much more readable in my specific case. ...

Challenges of Mocking Functions in Different Files When Testing with Jest

I'm currently facing a challenge with writing tests for the CreateVendor function using Jest and Supertest. My issue lies in how to effectively mock the dependencies (generateSalt, hashPassword) in order to correctly test the behavior of the function. ...

Creating a custom dropdown filter in ag-grid-angular

I am currently integrating 'ag-grid-angular' into my project. As for the filter display, I would like to replace the search box with a drop-down menu. Furthermore, I aim to populate this drop-down with unique elements from the specific column. H ...

TypeScript requires that the `includes` function must have the same type parameter for both input and

When working with TypeScript, I've encountered an interesting dilemma regarding the use of the Array.Prototype.includes function. It seems that this function requires me to pass in the same type as in the original array, but isn't the purpose of ...

Receiving an error response from the server upon subscribing to an Angular service (2/4/5/6)

I'm currently facing an issue with verifying my OTP. Depending on the response received from the server (whether it's due to OTP mismatch or OTP expiration), I need to display the appropriate error message. However, I am struggling to figure out ...

The issue of NestJS dependency injection not working within the MongooseModule.forFeatureAsync function call has been encountered

I'm having an issue setting up a pre-save hook on my User model. Here's the code snippet from my users.module.ts: @Module({ controllers: [ UsersController, ], exports: [ UsersService, ], providers: [ UsersService, ], imp ...

Exploring Angular: How to Access HTTP Headers and Form Data from POST Request

I am currently working with an authentication system that operates as follows: Users are directed to a third-party login page Users input their credentials The website then redirects the user back to my site, including an auth token in a POST request. Is ...

Guide on integrating an Excel file into the ag-grid-angular platform

I was looking for the import method, but I couldn't seem to find it. Does anyone have any idea where it is located? Please inform me! ...

utilizing tabview for component replacement

Having trouble changing components in Angular 7 with PrimeNG tabview tabs? Need some assistance? I have a setup with 3 components, and I want to switch between them when clicking on the panel inside the tabview. I've tried using onchange functions i ...

Angular does not render components when the URL changes during navigation

I am attempting to create a simple routing functionality in an Angular application by navigating through components using button clicks. Although the URL path changes, the content within the component's view is not being rendered. I have set up the a ...

Angular Universal causing issues with updating the DOM component

@Component({ selector: 'mh-feature-popup', template: ` <div class="full"> <div> <div class="container-fluid" [@featurepop]="state"> <div class="row"> <div class="col-xs-12 col-md-4 col-md-offse ...

An issue has arisen with loading chunks in Ionic 5/Angular, possibly due to an un

I am currently working on enhancing the offline capabilities of my Ionic 5 app. To achieve this, I have implemented a strategy where data is stored in SQLite while the app is connected, and then retrieved from SQLite when offline instead of making HTTP req ...