gpt4 book ai didi

javascript - 如何在node js xlsx npm中填充行的背景颜色

转载 作者:行者123 更新时间:2023-12-03 08:35:47 28 4
gpt4 key购买 nike

我需要读取 Excel 工作表,在检查后端数据后需要对行进行着色。我能够读取并使用新数据创建新工作表,但填充在此处不适用于单元格/行。

这是我的代码,我正在使用 xlsx npm

  let cell = workingSheet['C'+i];
console.log(cell)
workingSheet['A'+i].v = "PROCESSED"+i;
workingSheet['A'+i].s = { fill: { fgColor: { rgb: "#111111" } } };
console.log(
workingSheet['A'+i]
)
xlsx.writeFile(spreadsheet, `./sheets/output/mysheet.xls`);

最佳答案

此示例演示如何为单元格背景着色。问题是,没有图案类型:“solid”,并且颜色代码不需要开头#。这不适用于 xlsx 包,但适用于 xlsx-color

"use strict";
var xlsx = require("xlsx-color");
var spreadsheet = xlsx.utils.book_new();
var xf = "./sheets/output/mysheet.xls";

var sheets = {
"Munkafüzet1": [
["M1A1", "M1B1", "M1C1", "M1D1"],
["M1A2", "M1B2", "M1C2", "M1D2"],
["M1A2", "M1B2", "M1C2", "M1D2"],
["M1A2", "M1B2", "M1C2", "M1D2"],
["M1A2", "M1B2", "M1C2", "M1D2"],
]
};

for (var sheet of Object.keys(sheets)) {
xlsx.utils.book_append_sheet(
spreadsheet,
xlsx.utils.aoa_to_sheet(sheets[sheet]),
sheet
);
}

var i;
for (i = 1; i <= sheets["Munkafüzet1"].length; i++) {
spreadsheet.Sheets["Munkafüzet1"]["A"+i].s = {
fill: {
patternType: "solid",
fgColor: { rgb: "111111" }
}
};
}

xlsx.writeFile(spreadsheet, xf);

关于javascript - 如何在node js xlsx npm中填充行的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63920562/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com