-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Data validation list #347
Data validation list #347
Conversation
Hi @JanMarvin. This code works:
But the hyperlink doesn't work because it doesn't know to which tab from which worksheet it should point. But if I add this string to the formula directly in the R code, like this:
then I cannot open the Excel file anymore, it is corrupted. |
Sigh, it worked for me 😞 If you already know the file name, you could use the formula from your original post. I just wanted to be more flexible and use whatever sheet is available. I'll have a look at it tomorrow. |
Sorry... I just tried:
but I got the same result as before (corrupted). |
Even if the formula does not work for whatever reason, the data validation list does? |
Yes, it does. |
Alright, we'll figure it out :) Thanks for testing |
You're welcome, thanks for developing and improving! |
Guess that's it (tested in libreoffice). Formula expects escaped xml characters wb <- wb_workbook()$
add_worksheet("Tab_1", zoom = 80, gridLines = FALSE)$
add_data(x = rbind(2016:2019), dims = "C1:F1", colNames = FALSE)$
# add_data(x = 2017, startCol = 1, startRow = 1, colNames = FALSE)$
add_data_validation(rows = 1, col = 1, type = "list", value = '"2016,2017,2018,2019"')$
add_formula(startRow = 1, startCol = 2, x = '= HYPERLINK("#Tab_1!" & CELL("address", INDEX(C1:F1, MATCH(A1, C1:F1, 0))), "Go to the selected column")')
wb$open() |
Yes, well done! It also works on Excel 2007 now. |
Hehe, will fix this soon |
e7fd6d3
to
62553c0
Compare
The only remaining question is: what is the actual difference between old and new data validations list. I assume there must be a reason someone came up with the Though I guess this should be ready to merge. |
Hi @JanMarvin.
|
@olivier7121 , thanks for your kind words and that's because I sometimes have to sleep and a job to attend :) But to answer the question, the color does nothing aside from being blue. It does not impact the XLSX file in any other way. There already is a pull request to fix this #353 , but this needs to be updated again 🤷 While openxlsx2 is already well tested in many areas, I can't test everything and I have my own priorities and needs this package should fullfil. I almost exclusively need to load and read from workbooks. Everything else is just bonus to me. Therefore, I never saw the issue, because the files I was working with seldomly use hyperlinks and if they do, they already were colored. That's why raising issues is important. Just from the issues raised since the first CRAN release a couple of things have popped up. Like this here, or #356, #360, and #362. But they all require chunks of my time to research and fix. But we'll get there. |
Until this is fixed, you could use something like this: |
@JanMarvin I didn't see you opened a new issue #344 for that, and pulled a new request #353, many thanks once again!
Of course, that's fully understandable.
Yes, thank you, I already picked up the exact color of Excel hyperlinks :)
I would be happy to help with tests etc. |
@olivier7121 , if you want to have a look I've opened a pull request #365 this should fix a couple of issues with data styling including hyperlink styling. I've checked that a few of the basics still work, but this could use some additional testing. |
previously data_validation was an x14 extension which broke backward comparabilty with Excel 2007. Apparently this is not required.
compare old and new data validations list
969309f
to
727a48d
Compare
@olivier7121 merged it with main. Thanks again for bringing it to my attention. |
Hi @JanMarvin. Apologies for the late reaction, was ill and then quite busy with work.
I tried this code:
This worked both on Excel 2007 and Excel 2013 but without any blue-coloured hyperlinks in both cases. I first tried with the penultimate row like this (
But this didn't work at all on both versions of Excel I have on my computer. Is this what you wanted me to test? Or did I misunderstand? |
Hi @olivier7121 , all required pull requests should be merged with main already. If you want you can give that branch a spin. I plan to push 0.3.1 to CRAN this month, it will be picked from main. |
OK, I think what I tried was not correct then. I am not used to trying new versions on Github.
?
? |
Hi, you can simply build our current # this should be identical to ref = "main"
remotes::install_github("JanMarvin/openxlsx2", lib = "G:/Programmation/R/R-4.2.1/library") Or you could run the lines below to install from r-universe. No need to build on your end, similar to installation from CRAN: # Enable repository from janmarvin
options(repos = c(
janmarvin = 'https://janmarvin.r-universe.dev',
CRAN = 'https://cloud.r-project.org'))
# Download and install openxlsx2 in R
install.packages('openxlsx2') |
OK, thanks. I arrive at the same conclusion:
|
You have to use |
I obtain the same outcome. |
No no, I tried with Excel 2013 too ;) |
I run this code, minor adjustments from your code snippet (no whitespace in library(openxlsx2)
wb <- wb_workbook()$
add_worksheet("Tab_1", zoom = 80, gridLines = FALSE)$
add_data(x = rbind(2016:2019), dims = "C1:F1", colNames = FALSE)$
add_data(x = 2017, startCol = 1, startRow = 1, colNames = FALSE)$
add_data_validation(rows = 1, col = 1, type = "list", value = '"2016,2017,2018,2019"')$
add_formula(startRow = 1, startCol = 2, x = '=HYPERLINK("#Tab_1!" & CELL("address", INDEX(C1:F1, MATCH(A1, C1:F1, 0))), "Go to the selected column")')
wb$open() |
I tried with Excel 2007, 2013 and 365: with
|
I just meant: an |
Okay, sounds like you're still running the old openxlsx2 version. Please remove openxlsx2 entirely (enter the folder with the R libs. find openxlsx2, right click and delete the folder. after that run one of the solutions from above. |
OK, I thought that the previous version was replaced but apparently not. |
Glad that it works! And I know about the whitespace. It's required by our hyperlink detection :) |
Can you not perform a trimmed search? |
Have a look here: Lines 1036 to 1038 in 29ac147
If you have any other idea for this, please submit a pull request. I guess you can write the trimws wrapper around your hyperlink function if you need one. In all honesty, I do not care at all for hyperlinks or their colors and feel that I have spent already enough time on this issue. |
As you wish. I do care about hyperlinks (they are quite useful :D) and their color is here for a reason. |
Because it fixes another issue with formulas: #388 This will treat every cell with # works only with #388
wb <- wb_workbook()$
add_worksheet("Tab_1", zoom = 80, gridLines = FALSE)$
add_data(dims = "C1:F1", x = rbind(2016:2019), colNames = FALSE)$
add_data(x = 2017, startCol = 1, startRow = 1, colNames = FALSE)$
add_data_validation(rows = 1, col = 1, type = "list", value = '"2016,2017,2018,2019"')$
add_formula(dims = "B1", x = '=HYPERLINK("#Tab_1!" & CELL("address", INDEX(C1:F1, MATCH(A1, C1:F1, 0))), "Go to the selected column")')$
add_formula(dims = "B2", x = '=IF(2017 = VALUE(A1), HYPERLINK("github.com","github.com"), A1)') |
I don't understand your message (except the R code). |
Hi @olivier7121 ,
as discussed in ycphs/openxlsx#386 I've prepared a pull request to test if data valiadation lists work with Excel 2007. This is included in this pull request of
openxlsx2
. Please see the code below. This works in my MS365.To check:
If you could have a look. You can build with
ref="data_validation_list"
. Though we are currently in the process to release the package to CRAN and this pull request was a little late and needs some double checking.Todo