5

How does the code should look like to get cell A1 value from the file "C:\1.xlsx"? I tried numbers of examples but still didn't managed to get it work.

var Excel = require('exceljs');

var workbook = new Excel.Workbook();

workbook.xlsx.readFile("C:\1.xlsx")
    .then(function() {
        var worksheet = workbook.getWorksheet('Sheet1');
        var cell = worksheet.getCell('A1').value;
        console.log(cell);
    });

I see no errors, but it doesn't work.

F. Vosnim
  • 476
  • 2
  • 8
  • 23

3 Answers3

6

You have to access the worksheet first and then the cell. Like this:

var Excel = require('exceljs');
var workbook = new Excel.Workbook();
workbook.xlsx.readFile("C:/1.xlsx")
    .then(function() {
        ws = workbook.getWorksheet("Sheet1")
        cell = ws.getCell('A1').value
        console.log(cell)
    });

Replace "Sheet1" with the real sheet's name. You can also access the worksheet by id.

ws = workbook.getWorksheet(1)
R. Schifini
  • 9,085
  • 2
  • 26
  • 32
1

I guess you need to use getCell().value, like:

var cell = worksheet.getCell('C3').value;
Vasily Vlasov
  • 171
  • 13
0
await (new Promise((resolve, reject) => {
    var Excel = require('exceljs');
    var workbook = new Excel.Workbook();
    workbook.xlsx.readFile("C:/1.xlsx")
        .then(function() {
            ws = workbook.getWorksheet("Sheet1")
            cell = ws.getCell('A1').value
            console.log(cell)
            resolve()
        });
}));
F. Vosnim
  • 476
  • 2
  • 8
  • 23