我有一个很大的 Excel 表格(18k 行和 400 列),其中一些行使用不同的颜色突出显示。有没有办法使用按颜色过滤行openxlsx
?
我首先加载了工作簿
wb <- loadWorkbook(file = "Items Comparison.xlsx")
getStyles(wb)
df <- read.xlsx(wb, sheet = 1)
我看到工作簿中使用的样式使用getStyles(wb)
,但不确定如何使用该信息按颜色过滤每列的所有单元格。
[[1]]
A custom cell style.
Cell formatting: GENERAL
Font name: Tahoma
Font size: 9
Font colour: #FFFFFF
Font decoration: BOLD
Cell borders: Top: thin, Bottom: thin, Left: thin, Right: thin
Cell border colours: #4E648A, #4E648A, #4E648A, #4E648A
Cell vert. align: top
Cell fill foreground: rgb: #384C70
Cell fill background: rgb: #384C70
wraptext: TRUE
[[2]]
A custom cell style.
Cell formatting: GENERAL
Font name: Tahoma
Font size: 9
Font colour: #FFFFFF
Font decoration: BOLD
Cell borders: Top: thin, Bottom: thin, Left: thin, Right: thin
Cell border colours: #4E648A, #4E648A, #4E648A, #4E648A
Cell vert. align: top
Cell fill foreground: rgb: #384C70
Cell fill background: rgb: #384C70
wraptext: TRUE
我可以做什么来按填充颜色过滤数据?
UPDATE
基于@Henrik 解决方案,我尝试使用他的代码,但我不断收到错误。因此,为了了解发生了什么,我打印了输出x$style$fill$fillFg
rgb
"FF384C70"
rgb
"FF384C70"
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
rgb
"FF384C70"
NULL
NULL
NULL
rgb
"FFFFFF00"
rgb
"FFFFFF00"
theme
"0"
theme
"0"
rgb
"FFFFFF00"
NULL
theme
"2"
theme tint
"4" "0.79998168889431442"
theme
"8"
theme
"8"
rgb
"FFFFC000"
rgb
"FFFFC000"
theme tint
"5" "0.39997558519241921"
theme tint
"5" "0.39997558519241921"
theme tint
"9" "0.39997558519241921"
theme tint
"5" "0.79998168889431442"
rgb
"FFFFFF00"
rgb
"FF384C70"
NULL
NULL
NULL
rgb
"FF384C70"
rgb
"FF384C70"
[[1]]
rgb
"FF384C70"
[[2]]
rgb
"FF384C70"
[[3]]
NULL
[[4]]
NULL
[[5]]
NULL
[[6]]
NULL
[[7]]
NULL
[[8]]
NULL
[[9]]
NULL
[[10]]
NULL
[[11]]
NULL
[[12]]
NULL
[[13]]
rgb
"FF384C70"
[[14]]
NULL
[[15]]
NULL
[[16]]
NULL
[[17]]
rgb
"FFFFFF00"
[[18]]
rgb
"FFFFFF00"
[[19]]
theme
"0"
[[20]]
theme
"0"
[[21]]
rgb
"FFFFFF00"
[[22]]
NULL
[[23]]
theme
"2"
[[24]]
theme tint
"4" "0.79998168889431442"
[[25]]
theme
"8"
[[26]]
theme
"8"
[[27]]
rgb
"FFFFC000"
[[28]]
rgb
"FFFFC000"
[[29]]
theme tint
"5" "0.39997558519241921"
[[30]]
theme tint
"5" "0.39997558519241921"
[[31]]
theme tint
"9" "0.39997558519241921"
[[32]]
theme tint
"5" "0.79998168889431442"
[[33]]
rgb
"FFFFFF00"
[[34]]
rgb
"FF384C70"
[[35]]
NULL
[[36]]
NULL
[[37]]
NULL
[[38]]
rgb
"FF384C70"
[[39]]
rgb
"FF384C70"
我还是很困惑为什么只有 39 个项目。总行数是可变的,但不是 39。我也不理解该操作 - 是按行还是按列?