-
-
Save asiellb/90d7f5a54e58c81f28c0b9de8de9d175 to your computer and use it in GitHub Desktop.
Read/write xls files with Nodejs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'); | |
var Excel = require('exceljs'); | |
var app = express(); | |
app.listen(3000, function() { | |
console.log('Trying to read a xlsx file on port 3000...'); | |
var workbook = new Excel.Workbook(); | |
var filename = 'InputFile.xlsx'; | |
const COL = 'B'; | |
const ROW = 20; | |
// reading excel file | |
workbook.xlsx.readFile(__dirname + filename).then(function() { | |
// get the 2nd column ('input') | |
var worksheet = workbook.getWorksheet(1); | |
// get the B column | |
var col = worksheet.getColumn(COL); | |
// modify the B20 with 'No' | |
col.eachCell(function(cell, rowNumber) { | |
if (rowNumber == ROW) { | |
cell.value = 'No'; | |
} | |
}); | |
// save the content in a new file (formulas re-calculated) | |
workbook.xlsx.writeFile(__dirname + '/OutputFile.xlsx'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment