Reading the xlsx file using excelJS in Angular

I want to read a source file, edit it and then sent it to the user to download it. But I can't read the source file from the project. Here is an implementation of file reading in excelJS that I am using:

import {FormArray, FormControl, FormGroup, Validators} from '@angular/forms';
import { Component, OnInit} from '@angular/core';
import * as ExcelJS from "exceljs/dist/exceljs.min.js";


@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})

export class AppComponent implements OnInit {
  form: FormGroup
  stepCounter: number
  itemCounter: number
  data: dataInterface

  ngOnInit() {
    this.form = new FormGroup({
      companyName: new FormControl('', Validators.required),
      items: new FormArray([])
    })
    this.data = {}
    this.itemCounter = 0
    this.stepCounter = 1
    this.addItem()
    let workbook: ExcelJS.Workbook = new ExcelJS.Workbook();
    workbook.xlsx.readFile('/src/assets/sourceWorkbook.xlsx')
      .then(function() {
        console.log('Done!')
        console.log(workbook)
      });
  }

Also to add excelJS module I've added a string to angular.json:

"scripts": [
              "node_modules/exceljs/dist/exceljs.min.js"
            ]

The thing is that I've always got an error like this:

ERROR Error: "Uncaught (in promise): TypeError: i.constants is undefined
exists/<@http://localhost:4200/vendor.js:62894:86961
[email protected]://localhost:4200/polyfills.js:973:33
[email protected]://localhost:4200/vendor.js:62894:86936
e/<@http://localhost:4200/vendor.js:62894:383830
[email protected]://localhost:4200/vendor.js:62908:149223
s/o._invoke</<@http://localhost:4200/vendor.js:62908:148977
y/</e[t]@http://localhost:4200/vendor.js:62908:149580
[email protected]://localhost:4200/vendor.js:62894:382317
[email protected]://localhost:4200/vendor.js:62894:382521
i/</<@http://localhost:4200/vendor.js:62894:382580
[email protected]://localhost:4200/polyfills.js:973:33
i/<@http://localhost:4200/vendor.js:62894:382460
./node_modules/exceljs/dist/exceljs.min.js/</<[135]</</O</n<.value<@http://localhost:4200/vendor.js:62894:384180
[email protected]://localhost:4200/main.js:579:23
[email protected]://localhost:4200/vendor.js:10960:18
[email protected]://localhost:4200/vendor.js:10924:25
[email protected]://localhost:4200/vendor.js:10865:18
[email protected]://localhost:4200/vendor.js:17228:45
[email protected]://localhost:4200/vendor.js:17336:20
[email protected]://localhost:4200/vendor.js:18805:34
[email protected]://localhost:4200/vendor.js:18839:20
[email protected]://localhost:4200/vendor.js:20479:46
[email protected]://localhost:4200/vendor.js:45046:22
[email protected]://localhost:4200/vendor.js:45096:14
[email protected]://localhost:4200/vendor.js:45022:14
_moduleDoBootstrap/<@http://localhost:4200/vendor.js:44635:25
[email protected]://localhost:4200/vendor.js:44631:44
bootstrapModuleFactory/</</<@http://localhost:4200/vendor.js:44586:26
[email protected]://localhost:4200/polyfills.js:377:30
[email protected]://localhost:4200/vendor.js:43769:33
[email protected]://localhost:4200/polyfills.js:376:36
[email protected]://localhost:4200/polyfills.js:136:47
scheduleResolveOrReject/<@http://localhost:4200/polyfills.js:870:40
[email protected]://localhost:4200/polyfills.js:412:35
[email protected]://localhost:4200/vendor.js:43747:33
[email protected]://localhost:4200/polyfills.js:411:40
[email protected]://localhost:4200/polyfills.js:180:51
[email protected]://localhost:4200/polyfills.js:582:39

My file is located here: /src/assets/sourceWorkbook.xlsx

Answers:

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.