question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: e.createWriteStream is not a function

See original GitHub issue

Hi, I am trying to create a sample excel file but i am getting error ‘e.createWriteStream is not a function’. below is code to create the file-

import { Component } from '@angular/core';
import { NavController, Platform } from 'ionic-angular';
import * as Excel from "exceljs/dist/exceljs.min.js";
import * as ExcelProper from "exceljs";

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

  constructor(platform: Platform) {
    platform.ready().then(() => {
      this.createSheet();
    });
  }

  ionViewDidLoad() {
  }

  createSheet() {
    let workbook: ExcelProper.Workbook = new Excel.Workbook();
    var worksheet = workbook.addWorksheet('My Sheet');

    worksheet.columns = [
      { header: 'Id', key: 'id', width: 10 },
      { header: 'Name', key: 'name', width: 32 },
      { header: 'D.O.B.', key: 'DOB', width: 10 }
    ];
    worksheet.addRow({ id: 1, name: 'Ionic Android', dob: new Date(1970, 1, 1) });
    worksheet.addRow({ id: 2, name: 'Ionic iOS', dob: new Date(1965, 1, 7) });
    var tempFilePath = 'PATH/temp.xlsx'; // PATH is where you want to create your file

    workbook.xlsx.writeFile(tempFilePath).then(function () {
      console.log('file is written');
    });
  }
}

This is my ionic info output:

@ionic/cli-utils  : 1.19.0
    ionic (Ionic CLI) : 3.19.0

global packages:

    cordova (Cordova CLI) : 7.1.0

local packages:

    @ionic/app-scripts : 3.1.4
    Cordova Platforms  : android 6.3.0
    Ionic Framework    : ionic-angular 3.9.2

System:

    Android SDK Tools : 26.0.2
    Node              : v6.11.3
    npm               : 3.10.10
    OS                : Windows 7

Environment Variables:

    ANDROID_HOME : D:\ANDROID_SDK

Misc:

    backend : pro

Please help me to get out of this issue.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:6
  • Comments:12

github_iconTop GitHub Comments

73reactions
SyedAsimAliSEcommented, Apr 27, 2020

And here it is how to use with buffer !

import {saveAs} from "file-saver";

const buffer = await workbook.xlsx.writeBuffer();
const fileType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
const fileExtension = '.xlsx';

const blob = new Blob([buffer], {type: fileType});

saveAs(blob, 'fileName' + fileExtension);

11reactions
EdoAPPcommented, Aug 17, 2018

Hi @Ahmad19860, I don’t know if you could fix the problem but the problem is that you’re trying to execute a filesystem function on a webview.

The documentation says:

A portion of this library has been isolated and tested for use within a browser environment.

Due to the streaming nature of the workbook reader and workbook writer, these have not been included. Only the document based workbook may be used (see Create a Worbook for details).

For example code using ExcelJS in the browser take a look at the spec/browser folder in the github repo.

So, you wouuld need to use wb.xlsx.writeBuffer() instead of wb.xlsx.writeFile()

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught TypeError: fs.createWriteStream is not a function ...
I'm trying to export a formatted excel file using ExcelJS and the writeFile method simply isn't working.
Read more >
TypeError: e.createWriteStream is not a function - Bountysource
I am trying to create a sample excel file but i am getting error 'e.createWriteStream is not a function'. below is code to...
Read more >
TypeError: fs.createWriteStream is not a function in Node ...
I read through the Node documentation on fs and went through all the methods in the the fs/promises API and none of them...
Read more >
Node.js v19.3.0 Documentation
If the function has not been called exactly exact times when ... The following, for instance, will throw the TypeError because there is...
Read more >
Uncaught TypeError: fs.createWriteStream is not a function
Javascript – Uncaught TypeError: fs.createWriteStream is not a function ... I want to make a pdf file on client-side and afterwards it has...
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