Skip to content

Commit

Permalink
[R/wb_workbook] Remove r:Id from the pageSetup attributes. This attri…
Browse files Browse the repository at this point in the history
…bute was used only in conjunction with the removed printer binary. It was not noticed to be broken because the original pageSetup node was recently restored. fixes #216
  • Loading branch information
JanMarvin committed May 31, 2022
1 parent d47e907 commit 903c26a
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Expand Up @@ -2,6 +2,8 @@

## Fixes

* Fix an issue with broken pageSetup reference causing corupt excel files [216](https://github.com/JanMarvin/openxlsx2/issues/216)

* Fix reading and writing comments from workbooks that already provide comments [209](https://github.com/JanMarvin/openxlsx2/pull/209)

* Fix an issue with broken xml in Excels vml files and enable opening xlsm files with `wb$open()` [202](https://github.com/JanMarvin/openxlsx2/pull/202)
Expand Down
2 changes: 1 addition & 1 deletion R/class-workbook.R
Expand Up @@ -3539,7 +3539,7 @@ wbWorkbook <- R6::R6Class(

## Update ----
self$worksheets[[sheet]]$pageSetup <- sprintf(
'<pageSetup paperSize="%s" orientation="%s" scale = "%s" fitToWidth="%s" fitToHeight="%s" horizontalDpi="%s" verticalDpi="%s" r:id="rId2"/>',
'<pageSetup paperSize="%s" orientation="%s" scale = "%s" fitToWidth="%s" fitToHeight="%s" horizontalDpi="%s" verticalDpi="%s"/>',
paperSize, orientation, scale, as.integer(fitToWidth), as.integer(fitToHeight), hdpi, vdpi
)

Expand Down
2 changes: 1 addition & 1 deletion R/class-worksheet.R
Expand Up @@ -209,7 +209,7 @@ wbWorksheet <- R6::R6Class(
self$dataValidationsLst <- character()
self$hyperlinks <- list()
self$pageMargins <- '<pageMargins left="0.7" right="0.7" top="0.75" bottom="0.75" header="0.3" footer="0.3"/>'
self$pageSetup <- sprintf('<pageSetup paperSize="%s" orientation="%s" horizontalDpi="%s" verticalDpi="%s" r:id="rId2"/>', paperSize, orientation, hdpi, vdpi) ## will always be 2
self$pageSetup <- sprintf('<pageSetup paperSize="%s" orientation="%s" horizontalDpi="%s" verticalDpi="%s"/>', paperSize, orientation, hdpi, vdpi)
self$headerFooter <- hf
self$rowBreaks <- character()
self$colBreaks <- character()
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-helper_functions.R
Expand Up @@ -59,13 +59,13 @@ test_that("ws_page_setup example", {

## landscape page scaled to 50%
wb$page_setup(sheet = 1, orientation = "landscape", scale = 50)
exp <- "<pageSetup paperSize=\"9\" orientation=\"landscape\" scale = \"50\" fitToWidth=\"0\" fitToHeight=\"0\" horizontalDpi=\"300\" verticalDpi=\"300\" r:id=\"rId2\"/>"
exp <- "<pageSetup paperSize=\"9\" orientation=\"landscape\" scale = \"50\" fitToWidth=\"0\" fitToHeight=\"0\" horizontalDpi=\"300\" verticalDpi=\"300\"/>"
expect_equal(exp, wb$worksheets[[1]]$pageSetup)


## portrait page scales to 300% with 0.5in left and right margins
wb$page_setup(sheet = 2, orientation = "portrait", scale = 300, left = 0.5, right = 0.5)
exp <- "<pageSetup paperSize=\"9\" orientation=\"portrait\" scale = \"300\" fitToWidth=\"0\" fitToHeight=\"0\" horizontalDpi=\"300\" verticalDpi=\"300\" r:id=\"rId2\"/>"
exp <- "<pageSetup paperSize=\"9\" orientation=\"portrait\" scale = \"300\" fitToWidth=\"0\" fitToHeight=\"0\" horizontalDpi=\"300\" verticalDpi=\"300\"/>"
expect_equal(exp, wb$worksheets[[2]]$pageSetup)


Expand Down

0 comments on commit 903c26a

Please sign in to comment.