Uploaded template formatting is not preserved upon export
Expected Behavior
I expect that when I load an Excel template, add data to empty cells, and save the workbook, the text will be exported with the formatting outlined in the template. I also expect that any pre-existing text in the template will remain untouched, having the same formatting as it did in the template. Note that I only started noticing this recently, likely with the update. It used to work properly when I originally created it.
Actual Behavior
After adding data into empty cells and exporting the workbook, I get the Excel file stripped of the original text formatting across all tabs. Even adding data to just a single tab reverts the formatting on all tabs in the file. I've attached a sample template and an example of the output I get when running the code below so you can see what it's returning. I do use a lot of additional formatting arguments (styling) for data written into the other tabs starting in row 2, column 2, so I know how that works (not shown here), but I've never had an issue where it's a) changing cells that already exist and b) overruling the template formatting I've set for empty cells in the template.
Steps to Reproduce the Problem
Below is the simplest reprex from my code to see what's happening.
Sample template file (look at all tabs for original formatting; special attention to row 3, col 1 in the first tab where data is to be written): Sample_comments_template.xlsx
-
sample_file <- loadWorkbook("filepath.xlsx") #I have tried with isUnzipped = TRUE and FALSE with same result
-
writeData(sample_file, "Title", "Test Program", startCol = 1, startRow = 3, colNames = F)
-
saveWorkbook(sample_file, "new_filepath.xlsx", overwrite = TRUE) # overwrite = FALSE produces same result
Sample output file I get when running steps 1-3 (compare all tabs): Sample_comments_ouptut.xlsx
sessionInfo()
- Version of openxlsx: 4.2.4
- Version of R: 4.1.0
Hi @drsjp31 , please test with current master of the issue remains. This sounds like a fixed regression. The fix should be on Cran soon.
Is this fix on CRAN yet? Running into the same issue, also with version 4.2.4, though on R version 4.1.1
Unfortunately on our end life got in the way, though a fix should be on Cran soon. Until then please test if the issue remains with the current master branch.
Confirming issue was fixed with master
This issue is stale because it has been open 365 days with no activity. Remove stale label or comment or this will be closed in 7 days.
This issue was closed because it has been stalled for 7 days with no activity.