Skip to content
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

Adding a table where a column contains a formular with "<" results in an error. #841

Closed
mrainers opened this issue Nov 6, 2023 · 4 comments
Labels
duplicate 2️⃣ This issue or pull request already exists

Comments

@mrainers
Copy link

mrainers commented Nov 6, 2023

Let's say we want to add a table, where one column is an excel formula a suggested (and really nice) way to do so, is to add a "formula" class to that column:

wb <- wb_workbook()
wb$add_worksheet()

df = data.frame(x = 10,
                f = "A1<5")

class(df[["f"]]) <- c(class(df[["f"]]), "formula")

wb$add_data(x = df)

wb$open()

This works as long the formular does not contain a smaller than sign <. If it does, excel throws an error when trying to open the workbook.

The function wb$add_formula(x = "A1<5", dims = "B2") however works perfectly fine.

I guess this has something to do with parsing of the angle brackets?

Version Info

openxlsx2 : 1.1

@JanMarvin
Copy link
Owner

Thanks for the report @mrainers, but this was fixed with your last bug report.

library(openxlsx2)
wb <- wb_workbook()
wb$add_worksheet()

df = data.frame(x = 10,
                f = "A1<5")

class(df[["f"]]) <- c(class(df[["f"]]), "formula")

wb$add_data(x = df)

# works
wb$worksheets[[1]]$sheet_data$cc$f[4]
#> [1] "A1&lt;5"

@JanMarvin JanMarvin added the duplicate 2️⃣ This issue or pull request already exists label Nov 6, 2023
@JanMarvin
Copy link
Owner

Previous to the fix in #834 we would try to write "A1<5", which is not valid xml. The fix escapes the "<" correctly as "&lt;".

@mrainers
Copy link
Author

mrainers commented Nov 6, 2023

Allright, got the latest developement version and now it works :-)

@JanMarvin
Copy link
Owner

Glad you got it working! And sorry, apparently I was a little confused yesterday. #834 fixes a similar issue, but wasn't raised by you, but David Weisser on stackoverflow. Until the next release is deployed to CRAN, you could also write "A1 &lt; 5" in your formula. This escaped string will also be valid in future releases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate 2️⃣ This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants