ExcelJS with Angular and Typescript

See original GitHub issue

I’m working on integrating ExcelJS into a browser based node.js client built using the angular framework and typescript (and grunt). I previously tested the library in a separate project and was able to get it working using grunt with browserify, but this required me to bundle my own app.js script with a ‘require’ on the exceljs dependency.

My current project is designed to reference minified libraries by declaring script tags in index.html, and type definitions in a separate typings folder. I’ve done both for exceljs, but when I attempt to run my code (which declares a new Workbook via new Excel.Workbook()), I get the following error:

ReferenceError: Can't find variable: Excel in app/src/myScript.js (line 56)

Also Note: When I try and add a require statement on exceljs in the file that needs it, I get another ReferenceError:

ReferenceError: Can't find variable: require

What steps am I missing in integrating the library such that Excel will be recognized as the correct namespace? Or is there another way I should be declaring a Workbook?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:13

github_iconTop GitHub Comments

7reactions
IRCraziestTaxicommented, Aug 7, 2017

I have found a workaround for no type definitions:

import * as Excel from "exceljs/dist/exceljs.min.js";
import * as ExcelProper from "exceljs";

let workbook: ExcelProper.Workbook = new Excel.Workbook();

As long as you just use the import from exceljs for type definitions and only use functions from the import from exceljs/dist/exceljs.min.js, the app will run just fine and you still get type safety.

3reactions
Gargamilcommented, Jun 24, 2017

In which way you import exceljs?

I use ExcelJs in Angular (4) and TS too, with the following import:

import * as Excel from 'exceljs';

after that, you can use Exceljs:

const myWorkbook = new Excel.Workbook();

Read more comments on GitHub >

github_iconTop Results From Across the Web

Generating Excel File in Angular 9 Using “ExcelJs” - Devstringx
ExcelJS is the Javascript library used to read, write and manipulate the excel spreadsheet data and styles to JSON and XLSX. We can...
Read more >
Export Data to Excel in Angular Using ExcelJS | by Bharathiraja
Open the app.component.ts file and import the ExcelJS and File Saver plugin using the below code. Step 6.
Read more >
Create Excel from JSON in Angular 9/8 using Exceljs Tutorial ...
ExcelJS is the Javascript library used to read, manipulate, and write spreadsheet data and styles to XLSX and JSON. We can easily create...
Read more >
exceljs - npm
Read, manipulate and write spreadsheet data and styles to XLSX and JSON. Reverse engineered from Excel spreadsheet files as a project.
Read more >
Exporting Data to Excel file in Angular using ExcelJS
Generate Excel with Formatting · Import ExcelJS and FileSaver · Create a separate method and data variables. · Create Workbook and Add Worksheet....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found