workbook.addWorkSheet is not a function
See original GitHub issueBelow goes code I have written
'use strict';
const Hapi = require('hapi');
const Path = require('path');
var fs = require('fs');
var Excel = require('exceljs');
// create new server instance and connection information
const server = new Hapi.Server({
host: 'localhost',
port: 5009
})
//server.path(__dirname)
// Add the route
server.route({
method: 'GET',
path:'/path',
handler: function (request, h) {
let file = 'test.xlsx';
let filePath = Path.join(__dirname,file);
return 'file path - '+filePath;
}
});
server.route({
method: 'GET',
path: '/test.xlsx',
handler: function (request, h) {
let file = 'test.xlsx';
let filePath = Path.join(__dirname,file)
let contentType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
let data;
console.log(filePath)
fs.readFile(filePath, function(error, content) {
data = content;
});
console.log(data);
const res = h.response(data).type(contentType)
.header('Content-Disposition', 'attachment; filename=' + file);
console.log(res);
return res;
}
});
function createWorkBook(filePath) {
console.log("Inside the function createWorkBook");
var workbook = new Excel.Workbook();
console.log(workbook);
workbook.views = [
{
x: 0, y: 0, width: 10000, height: 20000,
firstSheet: 0, activeTab: 1, visibility: 'visible'
}
]
var worksheet = workbook.addWorkSheet("Data",{properties:{tabColor:{argb:'FFC0000'}}});
workbook.xlsx.writeFile(filePath)
.then(function() {
console.log("File created successfully")
});
}
// Start the server
async function start() {
try {
await server.start();
}
catch (err) {
console.log(err);
process.exit(1);
}
console.log('Server running at:', server.info.uri);
};
start();
createWorkBook(Path.join(__dirname,'data.xlsx'));
Below goes the error:
var worksheet = workbook.addWorkSheet("Fund Data",{properties:{tabColor:{argb:'FFC0000'}}});
^
TypeError: workbook.addWorkSheet is not a function at createWorkBook (C:\Work\FMS\src\core\server\hapiServer.js:82:34) at Object.<anonymous> (C:\Work\FMS\src\core\server\hapiServer.js:131:1) at Module._compile (module.js:635:30) at Object.Module._extensions…js (module.js:646:10) at Module.load (module.js:554:32) at tryModuleLoad (module.js:497:12) at Function.Module._load (module.js:489:3) at Function.Module.runMain (module.js:676:10) at startup (bootstrap_node.js:187:16) at bootstrap_node.js:608:3
Any help on this?
Issue Analytics
- State:
- Created 6 years ago
- Comments:10
Top Results From Across the Web
Undefined is not a function when creating a Workbook
When attempting to create an Excel spreadsheet in node.js, why does the following code not work?
Read more >@mmcraven/exceljs - npm
Sometimes (really very often) workbook has worksheets with id not starting from 1. // For instance It happens when any worksheet has been ......
Read more >How to download created excel file in node js using exceljs
I am using exceljs module for creating excel file. The problem is it is neither getting created nor getting saved in the path....
Read more >Code does not work in function node but works fine when run ...
Hi friends, I am using ExcelJS to write array to excel. and it's working fine when i run it using node exceltest.js const...
Read more >addWorksheet: Add a worksheet to a workbook in openxlsx
addWorksheet ( wb, sheetName, gridLines = openxlsx_getOp("gridLines", TRUE), ... sheet = 8, 1:400) ## Save workbook ## Not run: saveWorkbook(wb, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Can you please note how you solved it?
Update: While I haven’t tested it yet and am about to - I’m pretty confident I know what happened. In a nutshell: Operator error.
In a further summary: Lesson for today - when you are so used to Typescript catching the idiotic stuff instead of linting Javascript, quit being really get lazy and forgetting to check basic things. Such as:
Bottom line: Never mind.