awalker89 / openxlsx

R package for .xlsx file reading and writing.
Other
364 stars 79 forks source link

addStyle affects every sheet of a workbook instead of just the on declared #432

Open statzg opened 5 years ago

statzg commented 5 years ago

Expected Behavior

addStyle(wb, sheet=2, integerstyle, rows=5:16, cols=2, stack=TRUE) should affect only sheet 2 of a workbook and only the selected cells.

Actual Behavior

All sheets are affected by the second addStyle-command using a custom numFmt. The first addStyle affects only the declared cells, as expected, but the second addStyle affects all sheets and I think also all cells, that don't have a declared numFmt yet.

Steps to Reproduce the Problem

(please attach an example xlsx file if possible)

  1. create a workbook with multiple sheets using openxlsx, in my case 4 sheets. The one I use is attached here testfile.xlsx

  2. load worbbooks and add styles to certain cells

wb <- loadWorkbook(file = "testfile.xlsx")`
stringstyle <- createStyle(numFmt = "GENERAL")
integerstyle <- createStyle(numFmt = "#,##0")
teststyle <- createStyle(numFmt = "PERCENTAGE")
addStyle(wb, sheet=1, teststyle, rows=5:16, cols=2, stack=TRUE)
openXL(wb)
addStyle(wb, sheet=2, integerstyle, rows=5:16, cols=2, stack=TRUE)
openXL(wb)

sessionInfo()

Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 7 x64 (build 7601) Service Pack 1

timcois commented 3 years ago

I am experiencing the same issue. Has there been anyone looking further into this?

sdanchev commented 1 year ago

I also have the same problem. Has anyone found a solution? Thanks.