Feature: dropdown
#1084
-
Dear author @JanMarvin , For excel, there is a dropdown feature,like: I wonder if the |
Beta Was this translation helpful? Give feedback.
Answered by
JanMarvin
Jul 17, 2024
Replies: 2 comments 3 replies
-
There are various ways to create drop downs in library(openxlsx2)
gtcars <- gt::gtcars
make <- gtcars$mfr
car <- gtcars$model
df <- data.frame(
make, car
)
# there is some limit in MS365, maybe the string has to be < 254 characters?
list_sel <- paste0('"', paste0(car[1:32], collapse = ","), '"')
cat(list_sel)
#> "GT,458 Speciale,458 Spider,458 Italia,488 GTB,California,GTC4Lusso,FF,F12Berlinetta,LaFerrari,NSX,GT-R,Aventador,Huracan,Gallardo,Continental GT,Granturismo,Quattroporte,Ghibli,6-Series,i8,M4,M5,M6,DB11,Rapide S,Vanquish,Vantage,Corvette,Viper,R8,RS 7"
value_range <- paste0("'data'!", wb_dims(x = df, cols = "car"))
wb <- wb_workbook()$
add_worksheet("select")$
set_col_widths(cols = "A:B", widths = c(15, 20))$
add_data(dims = "A2:A4", x = c("with input string", "with input variable", "with sheet input", "form control"))$
add_data(dims = "D5", x = sample(seq_along(car), 1), col_names = FALSE)$
add_data_validation(dims = "B2", type = "list", value = '"GT,458 Speciale,458 Spider,458 Italia,488 GTB"')$
add_data_validation(dims = "B3", type = "list", value = list_sel)$
add_data_validation(dims = "B4", type = "list", value = value_range)$
add_form_control(dims = "B5", type = "Drop", range = value_range, link = "D5")$
add_worksheet("data")$
add_data(x = df)
if (interactive()) wb$open() |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
JanMarvin
-
Dear JanMarvin, Thank you for your code, and that meets my needs. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There are various ways to create drop downs in
openxlsx2
, please have a look if these can solve your request: