R,XLConnect:用RGB代码设置颜色
我遇到了以下问题。 大量的数据被写入Excel文件。 在书面的Excel表格中,我想将单元格颜色设置为非预定义的值(这是写入单元格的数字的函数)。 例如:给定单元格中的数字越高,单元格越绿。
我知道解决scheme存在的包xlsx
(见这里和这里 )。 但是我已经在整个项目中使用了XLConnect
,并且不想转换到目前为止所有的代码。
目前,我使用下面的代码来设置单元格颜色:
# create the excel workbook wb <- loadWorkbook("FILENAME.xls", create=TRUE)` # Create a CellStyle with yellow solid foreground CellColor <- createCellStyle(wb) setFillPattern(CellColor, fill = XLC$"FILL.SOLID_FOREGROUND") setFillForegroundColor(CellColor, color = XLC$"COLOR.YELLOW") # apply the CellStyle to a given cell, here: (10,10) setCellStyle(wb, sheet=SHEETNAME, row=10, col=10, cellstyle=CellColor) # save the workbook saveWorkbook(wb)
显然,有问题的部分是
color = XLC$"COLOR.YELLOW"
因为它不让我设置我喜欢的颜色的RGB代码。 尝试像
color = rgb(0.2,0.4,0.8)
失败。
第91页上的XLConnect文档只能说明这一点
通常通过来自XLC对象的相应颜色常数指定颜色。
没有解释如何使用RGB代码。