簡體   English   中英

獲取 excel 列作為數組 NodeJS

[英]Get excel column as array NodeJS

我有一個每天更新的 excel 表,我需要提取特定列的最后一個元素。 我正在使用 XLSX 節點模塊,但找不到任何方法來讀取工作表中的特定列。

這就是我的想法:

var wb = XLSX.readFile("test.xlsx", { cellDates: true });
var ws = wb.Sheets["Sheet1"];
const colArray = ws["B"]; //To get column B as an array

任何有解決這個問題的人嗎? 最好使用 XLSX 模塊。

提前致謝。

你可以這樣做

//Create an array with the object keys and filter "B" columns. Assign it to the variable "columnB"
let columnB = Object.keys(ws).filter(key => key[0] === "B");

//Get the last key name in your columnB variable.Assign it to the "lastElementKey" variable.
let lastElementKey = columnB[columnB.length -1];

//And lastly, this is your last element in column "B"
ws[lastElementKey]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM