1

请看下面的代码。我想从 xlsx 文件中读取数据,工作表名称为:WPA ext libs 2017.10.05。现在我想读取第一列的值。我应该在下面的代码中做哪些更改?

请参阅exceljs 链接

var Excel = require("exceljs");

var workbook = new Excel.Workbook();
workbook.xlsx.readFile("./CIoT_External Libraries & 3rd Party Content.xlsx")
.then(function(data){
    var worksheet = workbook.getWorksheet("WPA ext libs 2017.10.05");
    var lN = worksheet.getColumn(1);
    console.log(lN.collapsed);
});
4

2 回答 2

1

哟..我得到了答案。如果有人知道比这更好的答案,请告诉我。:)

var Excel = require("exceljs");

var workbook = new Excel.Workbook();
workbook.xlsx.readFile("./CIoT_External Libraries & 3rd Party Content.xlsx" )
    .then(function(data){
        var worksheet = workbook.getWorksheet("WPA ext libs 2017.10.05");
        for(var v=1;v<=worksheet.actualRowCount;v++)
        {
            var lN = worksheet.getCell("B"+v).value;
            console.log(" V :"+v+"------ Name :" +lN);
        }
});
于 2017-11-30T05:35:53.023 回答
0

使用 exceljs 循环遍历 excel 文件行的最佳方法是使用内置方法 .eachRow()

var Excel = require("exceljs");
var workbook = new Excel.Workbook();
workbook.xlsx.readFile("./CIoT_External Libraries & 3rd Party Content.xlsx" )
.then(function(data){
    var worksheet = workbook.getWorksheet("WPA ext libs 2017.10.05");

    worksheet.eachRow(function (row, rowNumber){
        // row_values contains the values, (first column is indexed by  
        var row_values = row_1.values;
        // Now you can access the columns directly by the column index
        Console.log("Value of Column B is : "+ row_values[2])
    }
 });
于 2019-05-08T15:13:43.140 回答