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

Document options #853

Merged
merged 5 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion R/class-comment.R
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ wb_comment <- function(text = NULL,
width = 2,
height = 4) {
# Code copied from the wbWorkbook
author <- author %||% Sys.getenv("USERNAME")
author <- author %||% Sys.getenv("USERNAME") %||% Sys.getenv("USER")
olivroy marked this conversation as resolved.
Show resolved Hide resolved
text <- text %||% ""
assert_class(author, "character")
assert_class(text, "character")
Expand Down
15 changes: 8 additions & 7 deletions R/class-workbook.R
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,12 @@ wbWorkbook <- R6::R6Class(
self$Content_Types <- genBaseContent_Type()

creator <- creator %||%
getOption("openxlsx2.creator") %||%
getOption("openxlsx2.creator", default = Sys.getenv("USERNAME")) %||%
# USERNAME may only be present for windows
Sys.getenv("USERNAME", Sys.getenv("USER"))
Sys.getenv("USER")

datetime_created <- getOption("openxlsx2.datetimeCreated", datetime_created)

datetime_created <- getOption("openxlsx2.datetimeCreated") %||%
datetime_created

assert_class(creator, "character")
assert_class(title, "character", or_null = TRUE)
Expand Down Expand Up @@ -4269,7 +4269,7 @@ wbWorkbook <- R6::R6Class(
done <- as_xml_attr(resolve)
if (reply) done <- NULL

ts <- getOption("openxlsx2.datetimeCreated") %||% Sys.time()
ts <- getOption("openxlsx2.datetimeCreated", default = Sys.time())

tc <- xml_node_create(
"threadedComment",
Expand Down Expand Up @@ -5587,8 +5587,9 @@ wbWorkbook <- R6::R6Class(
company = NULL
) {

datetime_created <- getOption("openxlsx2.datetimeCreated") %||%
datetime_created
datetime_created <-
getOption("openxlsx2.datetimeCreated", datetime_created)


core_dctitle <- "dc:title"
core_subject <- "dc:subject"
Expand Down
4 changes: 2 additions & 2 deletions R/conditional_formatting.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ cf_create_databar <- function(extLst, formula, params, sqref, values) {
newExtLst <- gen_databar_extlst(
guid = guid,
sqref = sqref,
posColor = posColor,
negColor = negColor,
posColor = posColor,
negColor = negColor,
values = values,
border = border,
gradient = gradient
Expand Down
7 changes: 6 additions & 1 deletion R/openxlsx2-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
#' * `options("openxlsx2.borderStyle" = "thin")`
#' * `options("openxlsx2.dateFormat" = "mm/dd/yyyy")`
#' * `options("openxlsx2.datetimeFormat" = "yyyy-mm-dd hh:mm:ss")`
#' * `options("openxlsx2.maxWidth" = NULL)` (Maximum width allowed in Excel is 250)
#' * `options("openxlsx2.minWidth" = NULL)`
#' * `options("openxlsx2.numFmt" = NULL)`
#' * `options("openxlsx2.paperSize" = 9)` corresponds to a A4 paper size
#' * `options("openxlsx2.orientation" = "portrait")` page orientation
Expand All @@ -81,7 +83,10 @@
#' `wbWorkbook` object with [wb_workbook()] or new comments with [wb_add_comment()]
#' * `options("openxlsx2.thread_id")` the default person id when adding a threaded comment
#' to a cell with [wb_add_thread()]
#'
#' * `options("openxlsx2.accountingFormat" = 4)`
#' * `options("openxlsx2.commaFormat" = 3)`
#' * `options("openxlsx2.percentageFormat" = 10)`
#' * `options("openxlsx2.scientificFormat" = 48)`
#' @name openxlsx2_options
NULL
# matches enum celltype
Expand Down
14 changes: 7 additions & 7 deletions R/write.R
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ write_data2 <- function(
}
}
if (any(dc == openxlsx2_celltype[["short_date"]])) { # Date
numfmt_dt <- getOption("openxlsx2.dateFormat") %||% 14
numfmt_dt <- getOption("openxlsx2.dateFormat", 14)

dim_sel <- get_data_class_dims("short_date")
# message("short_date: ", dim_sel)
Expand All @@ -513,7 +513,7 @@ write_data2 <- function(
)
}
if (any(dc == openxlsx2_celltype[["long_date"]])) {
numfmt_posix <- getOption("openxlsx2.datetimeFormat") %||% 22
numfmt_posix <- getOption("openxlsx2.datetimeFormat", default = 22)

dim_sel <- get_data_class_dims("long_date")
# message("long_date: ", dim_sel)
Expand All @@ -525,7 +525,7 @@ write_data2 <- function(
)
}
if (any(dc == openxlsx2_celltype[["hms_time"]])) {
numfmt_hms <- getOption("openxlsx2.hmsFormat") %||% 21
numfmt_hms <- getOption("openxlsx2.hmsFormat", default = 21)

dim_sel <- get_data_class_dims("hms_time")
# message("hms: ", dim_sel)
Expand All @@ -537,7 +537,7 @@ write_data2 <- function(
)
}
if (any(dc == openxlsx2_celltype[["accounting"]])) { # accounting
numfmt_accounting <- getOption("openxlsx2.accountingFormat") %||% 4
numfmt_accounting <- getOption("openxlsx2.accountingFormat", default = 4)

dim_sel <- get_data_class_dims("accounting")
# message("accounting: ", dim_sel)
Expand All @@ -548,7 +548,7 @@ write_data2 <- function(
)
}
if (any(dc == openxlsx2_celltype[["percentage"]])) { # percentage
numfmt_percentage <- getOption("openxlsx2.percentageFormat") %||% 10
numfmt_percentage <- getOption("openxlsx2.percentageFormat", default = 10)

dim_sel <- get_data_class_dims("percentage")
# message("percentage: ", dim_sel)
Expand All @@ -560,7 +560,7 @@ write_data2 <- function(
)
}
if (any(dc == openxlsx2_celltype[["scientific"]])) {
numfmt_scientific <- getOption("openxlsx2.scientificFormat") %||% 48
numfmt_scientific <- getOption("openxlsx2.scientificFormat", default = 48)

dim_sel <- get_data_class_dims("scientific")
# message("scientific: ", dim_sel)
Expand All @@ -572,7 +572,7 @@ write_data2 <- function(
)
}
if (any(dc == openxlsx2_celltype[["comma"]])) {
numfmt_comma <- getOption("openxlsx2.commaFormat") %||% 3
numfmt_comma <- getOption("openxlsx2.commaFormat", default = 3)

dim_sel <- get_data_class_dims("comma")
# message("comma: ", dim_sel)
Expand Down
4 changes: 2 additions & 2 deletions R/write_xlsx.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ write_xlsx <- function(x, file, as_table = FALSE, ...) {
}

creator <- creator %||%
getOption("openxlsx2.creator") %||%
getOption("openxlsx2.creator", default = Sys.getenv("USERNAME")) %||%
# USERNAME may only be present for windows
Sys.getenv("USERNAME", Sys.getenv("USER"))
Sys.getenv("USER")

#---add_worksheet---#
## sheetName
Expand Down
6 changes: 6 additions & 0 deletions man/openxlsx2_options.Rd

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