openxlsx icon indicating copy to clipboard operation
openxlsx copied to clipboard

Uploaded template formatting is not preserved upon export

Open drsjp31 opened this issue 4 years ago • 5 comments

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

  1. sample_file <- loadWorkbook("filepath.xlsx") #I have tried with isUnzipped = TRUE and FALSE with same result

  2. writeData(sample_file, "Title", "Test Program", startCol = 1, startRow = 3, colNames = F)

  3. 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

drsjp31 avatar Aug 17 '21 19:08 drsjp31

Hi @drsjp31 , please test with current master of the issue remains. This sounds like a fixed regression. The fix should be on Cran soon.

JanMarvin avatar Aug 17 '21 20:08 JanMarvin

Is this fix on CRAN yet? Running into the same issue, also with version 4.2.4, though on R version 4.1.1

jacksonsj avatar Oct 11 '21 20:10 jacksonsj

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.

JanMarvin avatar Oct 11 '21 21:10 JanMarvin

Confirming issue was fixed with master

jacksonsj avatar Oct 11 '21 21:10 jacksonsj

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.

github-actions[bot] avatar Oct 15 '22 03:10 github-actions[bot]

This issue was closed because it has been stalled for 7 days with no activity.

github-actions[bot] avatar Oct 29 '22 03:10 github-actions[bot]