Kannan Subramanian
Kannan Subramanian

Reputation: 250

R - Unable to select color using bgFill under createStyle command in openxlsx package

I am unable to select the color for the spreadsheet cells using the option bgFill.

wb <- loadWorkbook("workbook.xlsx")

s <- createStyle(bgFill = "#FFC7CE")
addStyle(wb,sheet = 1, s, cols=1:100, rows=1:100,gridExpand = TRUE)

Although I change the hex code on bgFill, my cells remain black in colour on the spreadsheet. I have tried predefined colours like red, green and blue too. I am unable to switch the colour of cells.

Upvotes: 5

Views: 2334

Answers (1)

DjibSA
DjibSA

Reputation: 301

For people who, years after, might encounter this problem like me...

As @IceCreamToucan states, you should use fgFill instead of bgFill which is for conditional formatting. Openxlsx documentation writes for the createStyle function (link):

bgFill:
Cell background fill colour. A valid colour (belonging to colours()) or a valid hex colour beginning with "#". – Use for conditional formatting styles only.

Upvotes: 7

Related Questions