我正在使用excel4node在nodeJS中创建Excel文件。 该网站提供了以下使用填充属性的指南。
fill: { // §18.8.20 fill (Fill)
type: string, // Currently only 'pattern' is implimented. Non- implimented option is 'gradient'
patternType: string, //§18.18.55 ST_PatternType (Pattern Type)
bgColor: string // HTML style hex value. optional. defaults to black
fgColor: string // HTML style hex value. required.
},
我无法解决这个问题。有人可以帮帮我吗?
答案 0 :(得分:14)
基本上,您可以对当前状态下的包执行以下操作:
fill: {
type: 'pattern', // the only one implemented so far.
patternType: 'solid', // most common.
fgColor: '2172d7', // you can add two extra characters to serve as alpha, i.e. '2172d7aa'.
// bgColor: 'ffffff' // bgColor only applies on patternTypes other than solid.
}
请注意,单元格的背景颜色将是fill属性的前景色(fgColor)。这听起来令人困惑,但是当您了解fill属性具有使用多种颜色的模式时,这是有道理的,因此该属性具有前景和背景颜色。
'solid'patternType可能是您正在寻找的,但还有其他的,例如'darkDown','darkHorizontal','lightGrid'等,如下所示: excel4node/fillPattern.js
答案 1 :(得分:0)
在excel内部定义函数,生成函数如下: ... var wb = new xl.Workbook(); var ws = wb.addWorksheet('每日活动报告');
function colorCell(color, pattern) {
return wb.createStyle({
fill: {
type: 'pattern',
fgColor: color,
patternType: pattern || 'solid',
}
});
}
然后像
一样应用ws.cell(1,1).string("Cell Content").style(colorCell('#CDDC39'))
(可选)您可以在函数参数中发送模式类型。