Last active
March 15, 2021 05:06
-
-
Save FSDevelop/ebcf8fcc581bdc0c9643 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'); | |
}); | |
}); |
Your solution is for .XLSX only, not for .XLS. These formats are different completely, just extensions are like
Oh, I didn't tried with xls, just xlsx, I tought it would work. My bad
Thank u
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Your solution is for .XLSX only, not for .XLS. These formats are different completely, just extensions are like