openxlsx
openxlsx copied to clipboard
class "percentage' corrupts workbook when zero is present
Version 4.0.17
I am sorry but I just don't have the time for a full write up.
Basically, whenever my "percentage" formatted column has a zero I get the correct excel message and the is formatted incorrectly:
Expected Behavior
Actual Behavior
Steps to Reproduce the Problem
(please attach an example xlsx file if possible)
sessionInfo()
- Version of openxlsx:
- Version of R:
Unable to reproduce this error with
wb <- createWorkbook("")
addWorksheet(wb, "sheet1")
df <- data.frame('p' = 0L)
class(df$p) <- "percentage"
writeData(wb, 1, df, colNames = FALSE)
openXL(wb)
wb <- createWorkbook()
addWorksheet(wb, "sheet1")
df <- data.frame('p' = seq(0, 1, length.out = 7))
class(df$p) <- c(class(df$p), "percentage")
writeData(wb, 1, df, colNames = T)
openXL(wb)
wb <- createWorkbook()
addWorksheet(wb, "sheet1")
df <- data.frame('p' = 0L)
addStyle(wb = wb, sheet = 1, style = createStyle(numFmt = "percentage"), cols = 1, rows = 1)
writeData(wb, 1, df, colNames = FALSE)
openXL(wb)
I can still reproduce within the context of a largish program but could not make a small example that shows the bug. Sorry.
I managed to create a small example (it seems to be reproducible) showing a bug described above.
library(openxlsx)
d = data.frame(
a = c('a','a'),
b = c(0,0.000123)
)
class(d$b) <- 'percentage'
write.xlsx(d,'table.xlsx')
Running under: Windows 10 x64
- Version of openxlsx: 4.1.0
- Version of R: 3.6.0