javascript - 使用带有 node.js 的模块 exceljs 从特定行/列开始写入数据
问题描述
我想从特定的行/列开始将数据写入 xlsx 文件。我找到了很多关于 exceljs 的网站,但没有一个对我有帮助。
for (let i = 0; i < people.length; i++) {
let {name, age} = people[i]
worksheet.addRow({name: name, age: age})
}
worksheet.eachRow(function(row, rowNumber) {
row.eachCell(function(cell, colNumber) {
// some code
}
}
解决方案
您可以使用 Excel JS API,代码示例显示了如何将数据写入特殊的行/列。要点可以在以下位置找到:https ://gist.github.com/lumine2008/796915d73a56a9e89ff9393c77845759
await Excel.run(async (context) => {
context.workbook.worksheets.getItemOrNullObject("Sample").delete();
const sheet = context.workbook.worksheets.add("Sample");
const data = [
["Product", "Qty", "Unit Price", "Total Price"],
["Almonds", 2, 7.5, "=C3 * D3"],
["Coffee", 1, 34.5, "=C4 * D4"],
["Chocolate", 5, 9.56, "=C5 * D5"]
];
const range = sheet.getRange("B2:E5");
range.values = data;
range.format.autofitColumns();
const header = range.getRow(0);
header.format.fill.color = "#4472C4";
header.format.font.color = "white";
sheet.activate();
await context.sync();
推荐阅读
- laravel - 创建模型方法在 Laravel 中返回一个整数
- python - 将枚举用于“单行循环”
- reactjs - 如何使用 jest 和 RTL 模拟来自反应组件的异步操作调用
- python - 在 JupyterNotebook 中导入 geopandas 时,有关 spatialindex_c.dll 的操作系统错误
- python - 用得到的结果覆盖文本文件
- php - 正则表达式以字母开头和结尾的显示名称
- java - Selenium 网格 - 测试不是并行运行,而是在每个模拟器上运行两次
- android - 我在尝试记录输出时收到“E/eglCodecCommon: GoldfishAddressSpaceHostMemoryAllocator: ioctl_ping failed for device_type=5, ret=-1”错误
- amazon-web-services - 在哪里可以找到具有更新值的 AWS CLI 文档?
- ubuntu - nodemon 应用程序崩溃 - 在启动之前等待文件更改 - Ubuntu npm start