Skip to content

Instantly share code, notes, and snippets.

@FSDevelop
Last active March 15, 2021 05:06
Show Gist options
  • Save FSDevelop/ebcf8fcc581bdc0c9643 to your computer and use it in GitHub Desktop.
Save FSDevelop/ebcf8fcc581bdc0c9643 to your computer and use it in GitHub Desktop.
Read/write xls files with Nodejs
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');
});
});
@xunter
Copy link

xunter commented Mar 28, 2019

Your solution is for .XLSX only, not for .XLS. These formats are different completely, just extensions are like

@FSDevelop
Copy link
Author

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

@23Alade
Copy link

23Alade commented Sep 8, 2020

Thank u

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment