如何使用来自节点的 "xlsx" 包从工作簿中的给定 .xlsx sheet 中提取单元格值?
How to extract a cell value from a given .xlsx sheet in a workbook using "xlsx" package from node?
我想使用 npm 模块“.xlsx”从工作簿中给定 sheet 的特定行和列中提取给定 .xlsx 文件的单元格值。请建议我提取值的任何方法,以便我可以使用 sheet.
中的测试数据
鉴于我能够去特定的 sheet
const xlsx =require("xlsx");
const wb=xlsx.readFile("test_data.xlsx");
const ws=wb.Sheets["Sheet1"]
试试用这个。你可以安装 const xlsx-populate
然后这个函数
XlsxPopulate.fromFileAsync("./Book1.xlsx")
.then(workbook => {
// choose the sheet and a cell.
const value = workbook.sheet("Sheet1").cell("A1").value();
console.log(value);
});
您可以将工作簿加载到内存中,检索 sheet,然后注销单元格以调试您正在查看的信息是否正确:
const workbook = xlsx.readFile('file path')
let worksheet = workbook.Sheets['Sheet name'];
let cell = worksheet['C3'].v; // Column C, Row 3 (assuming there's data there)
console.log('Cell data', cell)
如果一切正常,您可以在循环、地图或任何其他渲染方式中使用此信息。
我想使用 npm 模块“.xlsx”从工作簿中给定 sheet 的特定行和列中提取给定 .xlsx 文件的单元格值。请建议我提取值的任何方法,以便我可以使用 sheet.
中的测试数据鉴于我能够去特定的 sheet
const xlsx =require("xlsx");
const wb=xlsx.readFile("test_data.xlsx");
const ws=wb.Sheets["Sheet1"]
试试用这个。你可以安装 const xlsx-populate
然后这个函数
XlsxPopulate.fromFileAsync("./Book1.xlsx")
.then(workbook => {
// choose the sheet and a cell.
const value = workbook.sheet("Sheet1").cell("A1").value();
console.log(value);
});
您可以将工作簿加载到内存中,检索 sheet,然后注销单元格以调试您正在查看的信息是否正确:
const workbook = xlsx.readFile('file path')
let worksheet = workbook.Sheets['Sheet name'];
let cell = worksheet['C3'].v; // Column C, Row 3 (assuming there's data there)
console.log('Cell data', cell)
如果一切正常,您可以在循环、地图或任何其他渲染方式中使用此信息。