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

[wb_load] minimal workbook #810

Merged
merged 1 commit into from
Oct 2, 2023
Merged

[wb_load] minimal workbook #810

merged 1 commit into from
Oct 2, 2023

Conversation

JanMarvin
Copy link
Owner

This PR provides the safe part from #780

  • is_wbWorkbook() and
  • allows to set sheet = NULL in wb_load()

This is helpful to load a workbook without any sheet information. Think of it like this, you want only the sheet names in a hundred MB size xlsx file. Obviously you should be able to load all the sheets, but you shouldn't have to. The worksheet information is in workbook.xml so you do not need anything else. With this PR you can do the following:

# load only the bar minimum from a workbook
wb_load(x, sheet = NULL, data_only = TRUE)

Ideally this should be used in a few functions to restore a few openxlsx workflows like this - as suggested in our README

Furthermore, there are several ways to read certain information of an openxml spreadsheet without having opened it in a spreadsheet software before, e.g. to get the contained sheet names or tables.

Both of these should work interchangeable

library(openxlsx2)
example_file <- system.file("extdata", "openxlsx2_example.xlsx", package = "openxlsx2")
wb_load(example_file, sheet = NULL, data_only = TRUE)$get_sheet_names()
#>   Sheet1   Sheet2 
#> "Sheet1" "Sheet2"
wb_get_sheet_names(example_file)
#> Error: wb must be class wbWorkbook or R6

@JanMarvin JanMarvin changed the title [wb_load] [wb_load] minimal workbook Oct 2, 2023
@JanMarvin JanMarvin merged commit 1532bdf into main Oct 2, 2023
9 checks passed
@JanMarvin JanMarvin deleted the sheet_null branch October 2, 2023 13:02
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.

1 participant