openxlsx icon indicating copy to clipboard operation
openxlsx copied to clipboard

class "percentage' corrupts workbook when zero is present

Open PeterVermont opened this issue 7 years ago • 3 comments

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:

image

Expected Behavior

Actual Behavior

Steps to Reproduce the Problem

(please attach an example xlsx file if possible)

sessionInfo()

  • Version of openxlsx:
  • Version of R:

PeterVermont avatar Mar 27 '17 13:03 PeterVermont

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)

awalker89 avatar Jul 02 '17 03:07 awalker89

I can still reproduce within the context of a largish program but could not make a small example that shows the bug. Sorry.

PeterVermont avatar Aug 03 '17 18:08 PeterVermont

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')

table.xlsx

Running under: Windows 10 x64

  • Version of openxlsx: 4.1.0
  • Version of R: 3.6.0

dznsn avatar Jun 13 '19 21:06 dznsn