Title: | Extra Functions for the openxlsx2 package |
---|---|
Description: | Extends the openxlsx2 package with wrapper and helper functions designed to add new features and options when working with Excel workbooks. |
Authors: | Eli Pousson [aut, cre, cph] |
Maintainer: | Eli Pousson <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.0.0.9000 |
Built: | 2024-11-11 02:23:33 UTC |
Source: | https://github.com/elipousson/openxlsx2Extras |
marquee::marquee_parse()
to format Markdown textfmt_marquee_txt()
uses marquee::marquee_parse()
and
openxlsx2::fmt_txt()
to format Markdown text.
fmt_marquee_txt( text, ..., style = marquee::classic_style(), ignore_html = TRUE )
fmt_marquee_txt( text, ..., style = marquee::classic_style(), ignore_html = TRUE )
text |
A character string. The core quality of markdown is that any text is valid markdown so there is no restrictions on the content |
... |
Ignored at this time. For future use. |
style |
A style set such as |
ignore_html |
Should HTML code be removed from the output |
fmt_marquee_txt( "# ABC abc" )
fmt_marquee_txt( "# ABC abc" )
read_xlsx_ext()
uses openxlsx2::read_xlsx()
but allows use of a name
repair argument ("unique"
by default) to avoid blank ""
or NA
values
for column names.
read_xlsx_ext(file, ..., repair = "unique")
read_xlsx_ext(file, ..., repair = "unique")
file |
An xlsx file, wbWorkbook object or URL to xlsx file. |
... |
Arguments passed on to
|
repair |
Either a string or a function. If a string, it must be one of
The The options |
set_excel_fmt_class(data, cols, fmt_class = "currency", multiple = TRUE)
set_excel_fmt_class(data, cols, fmt_class = "currency", multiple = TRUE)
data |
A data frame with columns to format. |
cols |
Column names or numbers to modify. |
fmt_class |
Excel style class, one of: c("currency", "accounting",
"hyperlink", "percentage", "scientific", "formula"). Length is recycled to
match length of cols using |
multiple |
Whether |
set_excel_fmt_class()
applies a style to each specified column. See the
openxlsx2 documentation for more information on this feature:
https://janmarvin.github.io/openxlsx2/articles/openxlsx2_style_manual.html#numfmts2
openxlsx2::wb_add_data()
with extra featureswb_add_data_ext()
extends openxlsx2::wb_add_data()
to add data to a
workbook with special handling for sf input objects and labelled data.
wb_add_data_ext( wb, x, ..., start_row = 1, geometry = c("drop", "coords", "wkt"), labels = c("drop", "row_before"), call = caller_env() )
wb_add_data_ext( wb, x, ..., start_row = 1, geometry = c("drop", "coords", "wkt"), labels = c("drop", "row_before"), call = caller_env() )
wb |
A Workbook object containing a worksheet. |
x |
Object to be written. For classes supported look at the examples. |
... |
Arguments passed on to
|
start_row |
A vector specifying the starting row to write |
geometry |
String, one of "drop" (default), "coords", or "wkt". Both "coords" and "wkt" are not yet supported. |
labels |
Method for handling column labels. "drop" (default) or "row_before". If "row_before", insert column labels in the row before the column names. |
call |
The execution environment of a currently
running function, e.g. |
wb_add_marquee_text()
uses fmt_marquee_txt()
to add Markdown formatted
text to a Workbook. openxlsx2::wb_set_col_widths()
is applied to the
workbook to adjust widths for the specified columns. Set widths = NULL
to
disable this functionality.
wb_add_marquee_text( wb = NULL, text, sheet = current_sheet(), dims = NULL, ..., cols = 1, widths = "auto" )
wb_add_marquee_text( wb = NULL, text, sheet = current_sheet(), dims = NULL, ..., cols = 1, widths = "auto" )
wb |
A Workbook object containing a worksheet. |
text |
A character string. The core quality of markdown is that any text is valid markdown so there is no restrictions on the content |
sheet |
The worksheet to write to. Can be the worksheet index or name. |
dims |
Spreadsheet cell range that will determine |
... |
Arguments passed on to
|
cols |
Indices of cols to set/remove column widths. |
widths |
Width to set |
library(openxlsx2) wb_workbook() |> wb_add_worksheet() |> wb_add_marquee_text( text = " # Heading 1 Example text. ~~Strikethrough text~~ ## Heading 2 - Bulleted list item 1 - Nested bullet - Bulleted list item 2" )
library(openxlsx2) wb_workbook() |> wb_add_worksheet() |> wb_add_marquee_text( text = " # Heading 1 Example text. ~~Strikethrough text~~ ## Heading 2 - Bulleted list item 1 - Nested bullet - Bulleted list item 2" )
wb_save_ext()
is a helper function that fills in the file name when saving
based on the XSLX title. This function is not stable and may change in the
future.
wb_save_ext(wb, file = NULL, overwrite = TRUE, ...)
wb_save_ext(wb, file = NULL, overwrite = TRUE, ...)
wb |
A |
file |
A path to save the workbook to |
overwrite |
If |
... |
Arguments passed on to
|
library(openxlsx2) withr::with_tempdir({ wb_workbook( title = "Title used for output file" ) |> wb_add_worksheet() |> wb_save_ext() fs::dir_ls() })
library(openxlsx2) withr::with_tempdir({ wb_workbook( title = "Title used for output file" ) |> wb_add_worksheet() |> wb_save_ext() fs::dir_ls() })
write_xlsx_ext()
wraps wb_add_data_ext()
to provide an equivalent to
openxlsx2::write_xlsx()
with better support for sf and labelled data.
Arguments passed to openxlsx2::wb_workbook()
are ignored if x is a workbook
instead of a data frame.
write_xlsx_ext( x, file = NULL, as_table = FALSE, ..., creator = NULL, title = NULL, subject = NULL, category = NULL, datetime_created = Sys.time(), theme = NULL, keywords = NULL, start_row = 1, overwrite = TRUE, geometry = c("drop", "coords", "wkt"), labels = c("drop", "row_before"), call = caller_env() )
write_xlsx_ext( x, file = NULL, as_table = FALSE, ..., creator = NULL, title = NULL, subject = NULL, category = NULL, datetime_created = Sys.time(), theme = NULL, keywords = NULL, start_row = 1, overwrite = TRUE, geometry = c("drop", "coords", "wkt"), labels = c("drop", "row_before"), call = caller_env() )
x |
An object or a list of objects that can be handled by |
file |
An optional xlsx file name. If no file is passed, the object is not written to disk and only a workbook object is returned. |
as_table |
If |
... |
Arguments passed on to
|
creator |
Creator of the workbook (your name). Defaults to login username or |
title , subject , category , keywords
|
Additional workbook properties passed
to |
datetime_created |
The time of the workbook is created |
theme |
Optional theme identified by string or number. See Details for options. |
start_row |
A vector specifying the starting row to write |
overwrite |
If |
geometry |
String, one of "drop" (default), "coords", or "wkt". Both "coords" and "wkt" are not yet supported. |
labels |
Method for handling column labels. "drop" (default) or "row_before". If "row_before", insert column labels in the row before the column names. |
call |
The execution environment of a currently
running function, e.g. |