我想創建一個示例excel文件,但我得到錯誤'fs.createWriteStream不是一個函數'。下面 是代碼來創建文件 -Ionic | TypeError | fs.createWriteStream不是函數
import { Component } from '@angular/core';
import { NavController, Platform } from 'ionic-angular';
import * as Excel from "exceljs/dist/exceljs.js";
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
constructor(platform: Platform) {
platform.ready().then(() => {
this.createSheetUsingExcelJs();
});
}
ionViewDidLoad() {
}
createSheetUsingExcelJs() {
let 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 = 'C:/Users/mahmad/Downloads/temp.xlsx';
console.log(workbook);
workbook.xlsx.writeFile('temp.xlsx').then(function() {
console.log('file is written');
});
}
}
請提出一個解決方案來解決這個問題
我試着用命令,但現在我得到錯誤「遺漏的類型錯誤:無法讀取屬性未定義的‘原型’」。 – user320676
任何想法它扔在哪裏?也許值得提出一個github問題請求,如果問題與lib –
它被拋出啓動屏幕上。即使我的主頁構造函數沒有調用。 – user320676