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

Corrupted xlsx file when a string contains \024 #486

Closed
Mkranj opened this issue Jul 31, 2024 · 4 comments
Closed

Corrupted xlsx file when a string contains \024 #486

Mkranj opened this issue Jul 31, 2024 · 4 comments

Comments

@Mkranj
Copy link

Mkranj commented Jul 31, 2024

Describe the bug
I'm creating an Excel file based on data in a database. I have some strings describing addresses, so UTF8 characters are to be expected. For a certain subset, the exported xlsx file gets corrupted. I've narrowed it down so that the problem occurs when any string contains the characters \024.

To Reproduce

mydf <- data.frame(address = "Trg dr.\024Zarka Dolinara")

write.xlsx(mydf, "errors.xlsx")

And try to open the resulting file.

Expected behavior
File opens with the provided data.

Additional context
I'm getting the data from a database, so I can't really control if such characters ocurr. Ideally I'd like to avoid string substitutions before saving as an Excel file.
I also use the data as part of a Shiny application and there are no issues rendering to a table there.

@JanMarvin
Copy link
Collaborator

Hi @Mkranj , please try if this is resolved with openxlsx2. There are known issues with openxlsx.

@Mkranj
Copy link
Author

Mkranj commented Jul 31, 2024

Hi, thank you for the suggestion.
Changing the second line in my example to openxlsx2::write_xlsx(mydf, "errors2.xlsx") does work, the Excel file contains the column name and the string without the troublesome character.

I'll have to do some research for applying this to other programs, since I depend on other openxlsx functionalities that I hope are also available in openxlsx2, as well as taking the time to rewrite code to use the new package API.

@JanMarvin
Copy link
Collaborator

Great that it works! As a fallback you could write the file with openxlsx2 and read it with openxlsx. But lots of efforts went into openxlsx2 and it’s very unlikely that they get backported to openxlsx. Personally openxlsx is more or less in just maintenance mode. A few PR that are simple can be merged, but other than that, it’s now legacy software.

@Mkranj
Copy link
Author

Mkranj commented Jul 31, 2024

I see, thank you for your help once more :)

@Mkranj Mkranj closed this as completed Jul 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants