openxlsx icon indicating copy to clipboard operation
openxlsx copied to clipboard

dataValidation multiple cols pick not working properly

Open hjia222 opened this issue 4 years ago • 2 comments

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()

  • Version of openxlsx: 4.0.29 & 4.1.5
  • Version of R: 3.6.1

hjia222 avatar Aug 05 '20 03:08 hjia222

Could you please create this also at ycphs/openxlsx?

I am maintaining the active fork of the package.

ycphs avatar Oct 27 '20 08:10 ycphs

Just did, thanks!

hjia222 avatar Oct 27 '20 13:10 hjia222