Commit ae22a856 authored by Jalbert, Joe's avatar Jalbert, Joe
Browse files

Added conditonal coloring to coluns in wbsave

parent e6a4d961
......@@ -43,7 +43,11 @@ simplifyAppend <- function(input) {
#' @param AllFirst Places the all tab at the beginning of the tabs. If FALSE, placed at end. Only fucntions when IncludeAll==TRUE
#' @param AllName Allows the All Data tab to be renamed.
#' @param dollarCols Vector of strings specifying the columns to save as ACCOUNTING datatypes in Excel
#' @param percentCols Vector of strings specifying the columns to save as PERCENTAGE datatypes in Excel
#' @param percentCols Vector of strings specifying the columns to save as PERCENTAGE datatypes in Excel
#' @param condCols Vector of strings specifying the columns to apply conditional coloring to in Excel
#' @param condColors Vector of length 2 or 3 that defines the colors used in conditional formatting
#' @param lowBad When TRUE (default), colors low values the first color in the vector (Red by default), if false, inverts the vector
#' @param rule Allows specification of the conditional color numeric range. Defaults to min/max of column
#' @return Creates a Excel workbook from the supplied dataframe
#' @import tidyverse
......@@ -53,27 +57,38 @@ simplifyAppend <- function(input) {
#' @examples
wbsave=function(df,filename,sheetBy=NULL,keepNames=TRUE, overwrite=TRUE,
IncludeAll=TRUE,AllFirst=TRUE, AllName="All",
dollarCols=NULL, percentCols=NULL){
dollarCols=NULL, percentCols=NULL,
condCols=NULL, condColors=c("#F8696B","#FFEB84","#63BE7B"),
lowBad=TRUE, rule=NULL
if(keepNames==FALSE) {
if(!is.null(sheetBy)) {sheetBy=str_to_sentence(sheetBy)}
dollarColsSheet=dollarCols, percentColsSheet=percentCols){
TABLE_COLNAMES_STYLE=createStyle(fontSize=11, fontColour ="#44546A", borderColour = "#8EA9DB",
borderStyle = "thick", border="bottom", textDecoration = c("BOLD"))
#dollar formatting
DollarStyle <- createStyle(numFmt ="ACCOUNTING" )#"$ #,##0"
addStyle(wb, sheet = sheet, style=DollarStyle, rows=2:(nrow(df)+1), cols=dollarColNums, gridExpand = T)
#percent formatting
PercentStyle <- createStyle(numFmt = "0.0%")
addStyle(wb, sheet = sheet, style=PercentStyle, rows=2:(nrow(df)+1), cols=percentColNums, gridExpand = T)
#conditional formatting
if(lowBad==FALSE) {condColors=rev(condColors)}
for (j in condColNums) {
conditionalFormatting(wb, sheet = sheet, rows=2:(nrow(df)+1), cols=j,style=condColors, type='colourScale')
#column widths
addStyle(wb, sheet = sheet, style=TABLE_COLNAMES_STYLE, rows=1, cols=1:length(colnames(df)))
width_vec_header_all <- nchar(colnames(df)) + 2
......@@ -112,7 +127,6 @@ wbsave=function(df,filename,sheetBy=NULL,keepNames=TRUE, overwrite=TRUE,
saveWorkbook(wb, filename, overwrite=overwrite)
#' Creates a Report with t-tests for a Vector of Outcomes
#' @param df Dataframe to use for the report
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment