awalker89 / openxlsx

R package for .xlsx file reading and writing.
Other
365 stars 78 forks source link

1000 separator with tick not working #543

Closed arnyeinstein closed 2 years ago

arnyeinstein commented 2 years ago

Hi If I use the excel format #'##0, writing the data to excel doesn't show the correct format (e.g. '20 instead of 20). Either a bug, or I am missing something

library(openxlsx)

wb <- createWorkbook()
df <- c(1000, 20, -20, -0.1)
fmt_mil <- createStyle(numFmt = "#'##0", halign = "right")
fmt_mil1 <- createStyle(numFmt = "#`##0", halign = "right")
fmt_mil2 <- createStyle(numFmt = "#´##0", halign = "right")
addWorksheet(wb, "test")
writeData(wb, "test", df)
writeData(wb, "test", df, startCol = 2)
writeData(wb, "test", df, startCol = 3)
addStyle(wb, "test",style = fmt_mil,  rows = 1:4, cols =1, gridExpand = TRUE, stack = TRUE)
addStyle(wb, "test",style = fmt_mil1,  rows = 1:4, cols =2, gridExpand = TRUE, stack = TRUE)
addStyle(wb, "test",style = fmt_mil2,  rows = 1:4, cols =3, gridExpand = TRUE, stack = TRUE)
saveWorkbook(wb, "test.xlsx", overwrite = TRUE)

Renger

arnyeinstein commented 2 years ago

It was so simple: just use #,### on my European notebook did the trick and the tick magically appears. Perhaps, it would be good if this was mentioned in the manual.