如何使用 js-xlsx 将单元格值设置为字符串
此代码片段使用 js-xlsx 读取 XLSX 文件,将 C2 单元格设置为 abc123 并将结果写入另一个文件:
set_cell_string.js
const XLSX = require('xlsx');
const table = XLSX.readFile('mytable.xlsx');
// 使用第一个工作表
const sheet = table.Sheets[table.SheetNames[0]];
// 选项 1:如果你有数字行和列索引
sheet[XLSX.utils.encode_cell({r: 1 /* 2 */, c: 2 /* C */})] = {t: 's' /* type: string */, v: 'abc123' /* value */};
// 选项 2:如果你有类似 'C2' 或 'D15' 的单元格坐标
sheet['C2'] = {t: 's' /* type: string */, v: 'abc123' /* value */};
XLSX.writeFile(table, 'result.xlsx');Check out similar posts by category:
Javascript, NodeJS
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow