Skip to content

addStyle does not allow for rectangular inputs #492

@thisCoolNerd

Description

@thisCoolNerd

Describe the bug
addStyle accepts only one row across columns, one column across rows, or an equal number of columns and rows. It does not accept a combination (e.g., 15 rows across 4 columns).

To Reproduce
df <- data.frame(
Age = sample(18:65, 15), # Numeric column
Gender = sample(c("Male", "Female"), 15, replace = TRUE), # String column
Income = sample(20000:100000, 15), # Numeric column
Occupation = sample(c("Teacher", "Engineer", "Doctor", "Artist", "Scientist"), 15, replace = TRUE), # String column
Married = sample(c("Yes", "No"), 15, replace = TRUE), # String column
Children = sample(0:5, 15, replace = TRUE), # Numeric column
Owns_House = sample(c(TRUE, FALSE), 15, replace = TRUE), # Logical column
Owns_Car = sample(c(TRUE, FALSE), 15, replace = TRUE) # Logical column
)

sample_style <- createStyle(valign = "center", halign = "left")

Any empty Excel file can be uploaded here

xl_workbook <- loadWorkbook("excel_error_template.xlsx")
writeData(xl_workbook, "contacts", df, startCol = 1, startRow = 1, rowNames = F, colnames = T)

This is where I get an error

addStyle(xl_workbook, "contacts", sample_style, rows = c(2:nrow(df)), cols = c(1:ncol(df)))

This is the error

Error in addStyle(xl.workbook, tab.name, text_align, rows = c(1:nrow(table.df)), :
Length of rows and cols must be equal.

Expected behavior
I expected that it would apply the style across the selection. Instead, I had to create a loop to hack it, but it's not efficient.

Example files
excel_error_template.xlsx

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions