Skip to content

Commit

Permalink
create_tablestyle
Browse files Browse the repository at this point in the history
  • Loading branch information
JanMarvin committed May 14, 2023
1 parent bd66671 commit e0d08bf
Show file tree
Hide file tree
Showing 3 changed files with 200 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export(create_font)
export(create_hyperlink)
export(create_numfmt)
export(create_sparklines)
export(create_tablestyle)
export(current_sheet)
export(dataframe_to_dims)
export(delete_data)
Expand Down
144 changes: 144 additions & 0 deletions R/wb_styles.R
Original file line number Diff line number Diff line change
Expand Up @@ -768,3 +768,147 @@ create_dxfs_style <- function(
)

}

#' create tableStyle
#' @param name name
#' @param wholeTable wholeTable
#' @param headerRow headerRow
#' @param totalRow totalRow
#' @param firstColumn firstColumn
#' @param lastColumn lastColumn
#' @param firstRowStripe firstRowStripe
#' @param secondRowStripe secondRowStripe
#' @param firstColumnStripe firstColumnStripe
#' @param secondColumnStripe secondColumnStripe
#' @param firstHeaderCell firstHeaderCell
#' @param lastHeaderCell lastHeaderCell
#' @param firstTotalCell firstTotalCell
#' @param lastTotalCell lastTotalCell
#' @export
create_tablestyle <- function(
name,
wholeTable = NULL,
headerRow = NULL,
totalRow = NULL,
firstColumn = NULL,
lastColumn = NULL,
firstRowStripe = NULL,
secondRowStripe = NULL,
firstColumnStripe = NULL,
secondColumnStripe = NULL,
firstHeaderCell = NULL,
lastHeaderCell = NULL,
firstTotalCell = NULL,
lastTotalCell = NULL
){

Check warning on line 803 in R/wb_styles.R

View workflow job for this annotation

GitHub Actions / lint

file=R/wb_styles.R,line=803,col=2,[brace_linter] There should be a space before an opening curly brace.

Check warning on line 803 in R/wb_styles.R

View workflow job for this annotation

GitHub Actions / lint

file=R/wb_styles.R,line=803,col=2,[paren_body_linter] There should be a space between a right parenthesis and a body expression.

tab_wholeTable <- NULL
if (length(wholeTable)) {
tab_wholeTable <- xml_node_create(
"tableStyleElement",
xml_attributes = c(type = "wholeTable", dxfId = wholeTable))
}
tab_headerRow <- NULL
if (length(headerRow)) {
tab_headerRow <- xml_node_create(
"tableStyleElement",
xml_attributes = c(type = "headerRow", dxfId = headerRow))
}
tab_totalRow <- NULL
if (length(totalRow)) {
tab_totalRow <- xml_node_create(
"tableStyleElement",
xml_attributes = c(type = "totalRow", dxfId = totalRow))
}
tab_firstColumn <- NULL
if (length(firstColumn)) {
tab_firstColumn <- xml_node_create(
"tableStyleElement",
xml_attributes = c(type = "firstColumn", dxfId = firstColumn))
}
tab_lastColumn <- NULL
if (length(lastColumn)) {
tab_lastColumn <- xml_node_create(
"tableStyleElement",
xml_attributes = c(type = "lastColumn", dxfId = lastColumn))
}
tab_firstRowStripe <- NULL
if (length(firstRowStripe)) {
tab_firstRowStripe <- xml_node_create(
"tableStyleElement",
xml_attributes = c(type = "firstRowStripe", dxfId = firstRowStripe))
}
tab_secondRowStripe <- NULL
if (length(secondRowStripe)) {
tab_secondRowStripe <- xml_node_create(
"tableStyleElement",
xml_attributes = c(type = "secondRowStripe", dxfId = secondRowStripe))
}
tab_firstColumnStripe <- NULL
if (length(firstColumnStripe)) {
tab_firstColumnStripe <- xml_node_create(
"tableStyleElement",
xml_attributes = c(type = "firstColumnStripe", dxfId = firstColumnStripe))
}
tab_secondColumnStripe <- NULL
if (length(secondColumnStripe)) {
tab_secondColumnStripe <- xml_node_create(
"tableStyleElement",
xml_attributes = c(type = "secondColumnStripe", dxfId = secondColumnStripe))
}
tab_firstHeaderCell <- NULL
if (length(firstHeaderCell)) {
tab_firstHeaderCell <- xml_node_create(
"tableStyleElement",
xml_attributes = c(type = "firstHeaderCell", dxfId = firstHeaderCell))
}
tab_lastHeaderCell <- NULL
if (length(lastHeaderCell)) {
tab_lastHeaderCell <- xml_node_create(
"tableStyleElement",
xml_attributes = c(type = "lastHeaderCell", dxfId = lastHeaderCell))
}
tab_firstTotalCell <- NULL
if (length(firstTotalCell)) {
tab_firstTotalCell <- xml_node_create(
"tableStyleElement",
xml_attributes = c(type = "firstTotalCell", dxfId = firstTotalCell))
}
tab_lastTotalCell <- NULL
if (length(lastTotalCell)) {
tab_lastTotalCell <- xml_node_create(
"tableStyleElement",
xml_attributes = c(type = "lastTotalCell", dxfId = lastTotalCell))
}

xml_elements <- c(

Check warning on line 884 in R/wb_styles.R

View workflow job for this annotation

GitHub Actions / lint

file=R/wb_styles.R,line=884,col=19,[object_usage_linter] missing arguments not allowed in calls to ‘c’
tab_wholeTable,
tab_headerRow,
tab_totalRow,
tab_firstColumn,
tab_lastColumn,
tab_firstRowStripe,
tab_secondRowStripe,
tab_firstColumnStripe,
tab_secondColumnStripe,
tab_firstHeaderCell,
tab_lastHeaderCell,
tab_firstTotalCell,
tab_lastTotalCell,
)

xml_node_create(
"tableStyle",
xml_attributes = c(
name = name,
pivot = "0", # pivot uses different styles
count = as_xml_attr(length(xml_elements)),
`xr9:uid` = sprintf(
"{CE23B8CA-E823-724F-9713-%s}",
random_string(length = 12, pattern = "[A-Z0-9]")
)
),
xml_children = xml_elements
)

}
55 changes: 55 additions & 0 deletions man/create_tablestyle.Rd

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

0 comments on commit e0d08bf

Please sign in to comment.