In this article, we saw how to export the word file of the data. In this article, we generate a Word file on the client-side.
Client Side Download Word: It’s helpful to reduce the API call on the server and then download.
In this article, we use 2 libraries “docx” & “FileSaver”. Let’s start to create a new project then install these modules.
ng new wordfile-generate
“wordfile-generate” you need to write your application’s name. Then it will take some time to create the project. After successfully installing that, you need to go to their directory. For example “cd wordfile-generate”. To Run angular applications, it required to run “ng serve”.
After we need to install “docx” & “FileSaver”
npm i docx
npm i file-saver
After install module. we create class for download the word file.
We need to import “docx” & “file-saver”
import { Packer } from "docx";
import * as fs from 'file-saver';
Let’s create app.component.ts ,DocGenerator class & app.component.html. Display in the below code.
Below is the full embeded code export Word file in Angular using “docx” & “FileSaver”. you can easily used in your application.
Example