Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create chartsheets. closes 464 #466

Merged
merged 12 commits into from
Dec 17, 2022
Merged

create chartsheets. closes 464 #466

merged 12 commits into from
Dec 17, 2022

Conversation

JanMarvin
Copy link
Owner

@JanMarvin JanMarvin commented Dec 9, 2022

library(openxlsx2)
library(mschart)

# broken unless mschart is added
wb <- wb_workbook()$
  add_worksheet("A & B")$
  add_data(x = mtcars)$
  add_chartsheet()

# create wb_data object
dat <- wb_data(wb, 1, dims = "A1:E6")

# call ms_scatterplot
data_plot <- ms_scatterchart(
  data = dat,
  x = "mpg",
  y = c("disp", "hp"),
  labels = c("disp", "hp")
)

wb$add_mschart(graph = data_plot)

wb$open()

* [ ] warning if no chart found on Chartsheet. sometime in the future we can provide a default Chartsheet and update the Chartsheet if a chart is assigned to an already existing Chartsheet

  • update NEWs

@JanMarvin
Copy link
Owner Author

@jmbarbone could you have a look why, in the example above, the sheet has to be selected? If I write this wb$add_mschart(graph = data_plot), current_sheet() evaluates to 1 and the workbook is damaged. It must be caused by the waiver code, but I could not understand what was going on.
If changing the behavior would cause other troubles, we can keep things the way they are. Most likely adding chartsheets is not of broad user interest.

@JanMarvin JanMarvin changed the title [WIP] create chartsheets. closes 464 create chartsheets. closes 464 Dec 13, 2022
@jmbarbone
Copy link
Collaborator

@JanMarvin The current sheet is reset in wb_data() because we call something there. This I guess is more like a "last_called_sheet()" which doesn't seem right.

library(openxlsx2)
wb <- wb_workbook()
wb$.__enclos_env__$private$current_sheet
#> [1] 0
wb$add_worksheet()
wb$.__enclos_env__$private$current_sheet
#> [1] 1
wb$add_data(x = mtcars)
wb$.__enclos_env__$private$current_sheet
#> [1] 1
wb$add_chartsheet()
wb$.__enclos_env__$private$current_sheet
#> [1] 2

# create wb_data object
dat <- wb_data(wb, 1, dims = "A1:E6")
wb$.__enclos_env__$private$current_sheet
#> [1] 1

Created on 2022-12-13 with reprex v2.0.2

Might also be worth it to have a $get_current_sheet() method to check this a little more easily

@JanMarvin
Copy link
Owner Author

Ah thanks, I completely missed that.

@JanMarvin
Copy link
Owner Author

The above code works now. Fixed wb_data() in #462

R/class-workbook.R Outdated Show resolved Hide resolved
@JanMarvin JanMarvin force-pushed the gh_issue_464 branch 2 times, most recently from 39517f0 to 74d4554 Compare December 14, 2022 19:51
@JanMarvin JanMarvin merged commit ca320b6 into main Dec 17, 2022
@JanMarvin JanMarvin deleted the gh_issue_464 branch December 17, 2022 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants