awalker89 / openxlsx

R package for .xlsx file reading and writing.
Other
363 stars 79 forks source link

dataValidation multiple cols pick not working properly #516

Open hjia222 opened 3 years ago

hjia222 commented 3 years ago

Expected Behavior

cols = c(5, 10, 15) should apply the drop down list to coulmns 5, 10, 15

Actual Behavior

cols = c(5, 10, 15) applied the drop down list to coulmns 5:15

Steps to Reproduce the Problem

library(openxlsx)

df <- bind_cols(iris, iris, iris)

# create workbook
wb <- createWorkbook()

# initialize worksheet
addWorksheet( wb = wb, sheetName = "Sheet1" )

# add df to Sheet1
writeData( wb = wb
           , sheet = "Sheet1"
           , x = df
)

## Add dropdown list

addWorksheet(wb, "comment values")

comment <- data.frame(comments = unique(iris$Species))
col_n <- which(str_detect(names(df), "Species"))

writeData(wb, sheet = "comment values", comment, startCol = 1)

dataValidation(wb, 1, cols = col_n, rows = 2:(nrow(df)+1),
               type = "list", value = "'comment values'!$A$2:$A$4")

openXL( file = wb )

sessionInfo()

ycphs commented 3 years ago

Could you please create this also at ycphs/openxlsx?

I am maintaining the active fork of the package.

hjia222 commented 3 years ago

Just did, thanks!