-
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
text cell to numeric conversion #384
Comments
Hello! I would like to know which function does this conversion. I tried using |
Hi @stees , good question. We haven’t really documented this, but have a look at this. options(“openxlsx2.string_nums“ = TRUE)
wb <- wb_workbook()$add_worksheet()$add_data(x = data.frame(v1 = as.character(1:5))) this should convert the strings to numerics. Typing on my phone, didn’t check this … is this what you were looking for? |
Actually, I was looking for something more in the lines of That's because the input dataframe had to store these columns as character columns in the first place already, so that's why converting the columns of the dataframe itself wouldn't do, I guess. Seeing as Excel allows for cell-specific types, I would like to convert only some of them, after applying other formatting functions (font, fill, etc). Using |
The thing is, strings are stored differently in the openxml format. Numbers are stored as [edit] for the option above: If the cell can be converted to a number and no NA is thrown in the process, the numeric value is written into the cell, otherwise the string is written. That’s why I think it’s what you wanted. |
Oh, I see. I'll try using that function and binding rows afterwards to see if it works. Thanks. |
I have added a first draft of a chapter for this to the book: https://janmarvin.github.io/ox2-book/chapters/openxlsx2_number_and_string.html |
|
Glad that it works! You should be able to change the number format with |
Idea from ycphs/openxlsx#195
We could provide a function that converts a range of cells or a sheet from text to numbers.
For this to work, we could convert characters to numbers, check for warnings, and if no warning is issued, replace the character contents of the cell with a numeric value.
The text was updated successfully, but these errors were encountered: