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

Misc doc edits #936

Merged
merged 3 commits into from Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions R/class-workbook-wrappers.R
Expand Up @@ -1046,6 +1046,9 @@ wb_remove_row_heights <- function(wb, sheet = current_sheet(), rows) {
#' and DPI settings used. Setting `widths` to specific value also is no guarantee
#' that the output will have consistent column widths.
#'
#' For automatic text wrapping of columns use
#' [wb_set_cell_style(wrap_text = TRUE)][wb_set_cell_style()]
#'
#' @param wb A `wbWorkbook` object.
#' @param sheet A name or index of a worksheet, a vector in the case of `remove_`
#' @param cols Indices of cols to set/remove column widths.
Expand Down
49 changes: 47 additions & 2 deletions R/class-workbook.R
Expand Up @@ -2,10 +2,55 @@

# R6 class ----------------------------------------------------------------
# Lines 7 and 8 are needed until r-lib/roxygen2#1504 is fixed
#' R6 class for a workbook
#' Workbook class
#'
#' @description
#' A workbook. The documentation is more complete in each of the wrapper functions.
#' This is the class used by `openxlsx2` to modify workbooks from R.
#' You can load an existing workbook with [wb_load()] and create a new one with
#' [wb_workbook()].
#'
#' After that, you can modify the `wbWorkbook` object through two primary methods:
#'
#' *Wrapper Function Method*: Utilizes the `wb` family of functions that support
#' piping to streamline operations.
#' ``` r
#' wb <- wb_workbook(creator = "My name here") %>%
#' wb_add_worksheet(sheet = "Expenditure", grid_lines = FALSE) %>%
#' wb_add_data(x = USPersonalExpenditure, row_names = TRUE)
#' ```
#' *Chaining Method*: Directly modifies the object through a series of chained
#' function calls.
#' ``` r
#' wb <- wb_workbook(creator = "My name here")$
#' add_worksheet(sheet = "Expenditure", grid_lines = FALSE)$
#' add_data(x = USPersonalExpenditure, row_names = TRUE)
#' ```
#'
#' While wrapper functions require explicit assignment of their output to reflect
#' changes, chained functions inherently modify the input object. Both approaches
#' are equally supported, offering flexibility to suit user preferences. The
#' documentation mainly highlights the use of wrapper functions.
#'
#' ``` r
#' # Import workbooks
#' path <- system.file("extdata/openxlsx2_example.xlsx", package = "openxlsx2")
#' wb <- wb_load(path)
#'
#' ## or create one yourself
#' wb <- wb_workbook()
#' # add a worksheet
#' wb$add_worksheet("sheet")
#' # add some data
#' wb$add_data("sheet", cars)
#' # Add data with piping in a different location
#' wb <- wb %>% wb_add_data(x = cars, dims = wb_dims(from_col = "D", from_row = 4))
#' # open it in your default spreadsheet software
#' if (interactive()) wb$open()
#' ```
#'
#' Note that the documentation is more complete in each of the wrapper functions.
#' (i.e. `?wb_add_data` rather than `?wbWorkbook`).
#'
#' @param creator character vector of creators. Duplicated are ignored.
#' @param dims Cell range in a sheet
#' @param sheet The name of the sheet
Expand Down
8 changes: 4 additions & 4 deletions R/wb_styles.R
Expand Up @@ -164,7 +164,7 @@ create_border <- function(
return(border)
}

#' create number format
#' Create number format
#' @param numFmtId an id, the list can be found in the **Details** of [create_cell_style()]
#' @param formatCode a format code
#' @seealso [wb_add_numfmt()]
Expand All @@ -184,7 +184,7 @@ create_numfmt <- function(numFmtId, formatCode) {
return(numfmt)
}

#' create font format
#' Create font format
#' @param b bold
#' @param charset charset
#' @param color rgb color: default "FF000000"
Expand Down Expand Up @@ -322,7 +322,7 @@ create_font <- function(
return(font)
}

#' create fill
#' Create fill pattern
#'
#' @param gradientFill complex fills
#' @param patternType various: default is "none", but also "solid", or a color like "gray125"
Expand Down Expand Up @@ -808,7 +808,7 @@ create_dxfs_style <- function(

# nocov start

#' create custom (pivot) table styles
#' Create custom (pivot) table styles
#'
#' Create a custom (pivot) table style.
#' These functions are for expert use only. Use other styling functions instead.
Expand Down
2 changes: 1 addition & 1 deletion README.Rmd
Expand Up @@ -55,7 +55,7 @@ install.packages('openxlsx2')

`openxlsx2` aims to be the swiss knife for working with the openxml spreadsheet formats xlsx, xlsm and (limited) xlsb (other formats of other spreadsheet software are not supported). We offer two different variants how to work with `openxlsx2`.

* The first one is to simply work with R objects. It is possible to read ([`read_xlsx()`](https://janmarvin.github.io/openxlsx2/reference/read_xlsx.html)) and write ([`write_xlsx()`](https://janmarvin.github.io/openxlsx2/reference/write_xlsx.html)) data from and to files. We offer a number of options in the commands to support various features of the openxml format, including reading and writing named ranges and tables. 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.
* The first one is to simply work with R objects. It is possible to read ([`read_xlsx()`](https://janmarvin.github.io/openxlsx2/reference/wb_to_df.html) and write ([`write_xlsx()`](https://janmarvin.github.io/openxlsx2/reference/write_xlsx.html)) data from and to files. We offer a number of options in the commands to support various features of the openxml format, including reading and writing named ranges and tables. 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.
* As a second variant `openxlsx2` offers the work with so called [`wbWorkbook`](https://janmarvin.github.io/openxlsx2/reference/wbWorkbook.html) objects. Here an openxml file is read into a corresponding `wbWorkbook` object ([`wb_load()`](https://janmarvin.github.io/openxlsx2/reference/wb_load.html)) or a new one is created ([`wb_workbook()`](https://janmarvin.github.io/openxlsx2/reference/wb_workbook.html)). Afterwards the object can be further modified using various functions. For example, worksheets can be added or removed, the layout of cells or entire worksheets can be changed, and cells can be modified (overwritten or rewritten). Afterwards the `wbWorkbook` objects can be written as openxml files and processed by suitable spreadsheet software.

Many examples how to work with `openxlsx2` are in our [manual pages](https://janmarvin.github.io/openxlsx2/reference/index.html) and in our [vignettes](https://janmarvin.github.io/openxlsx2/articles/). You can find them under:
Expand Down
19 changes: 11 additions & 8 deletions _pkgdown.yml
Expand Up @@ -2,6 +2,11 @@ url: https://janmarvin.github.io/openxlsx2

destination: docs

home:
links:
- text: Learn more
href: https://janmarvin.github.io/ox2-book/

template:
bootstrap: 5

Expand Down Expand Up @@ -49,22 +54,20 @@ reference:
contents:
- has_concept("worksheet content functions")

- subtitle: Add images to a worksheet
- subtitle: Add images and charts to a worksheet
desc: >
Add images or Excel charts to a worksheet with the mschart package.
See `vignette("openxlsx2_charts_manual")`.
contents:
- wb_add_image
- wb_add_plot

- subtitle: Add charts to worksheets
desc: >
Add Excel charts to a worksheet with the mschart package.
contents:
- wb_add_chartsheet
- wb_add_mschart


- title: Style a workbook
desc: >
Style a cell region, a worksheet or the entire workbook
Style a cell region, a worksheet or the entire workbook.
See `vignette("openxlsx2_style_manual")`.

- subtitle: Worksheet styling
desc: >
Expand Down
3 changes: 3 additions & 0 deletions man/col_widths-wb.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/create_fill.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/create_font.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/create_numfmt.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/tablestyle.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 46 additions & 2 deletions man/wbWorkbook.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.