Adding Empty Rows #1190
-
Hey guys, I'm trying to create Excel Files using some Templates I created. Those Templates are excel files, which include "placeholder"patterns, like "##TABLE1##". Were the placeholder is, my data should be inserted. What makes it a little more difficult is, that my data can have different length. When I use wb_add_data, it just overwrites everything coming after the wildcard. Is there a possibility to add empty rows? Or is there a different solution? If someone could help me, I would be really thankful! Best wishes, My code: library(openxlsx2)
# Load Template to Workboak
file_name <- "template.xlsx"
sheet_name <- "sheet1"
wb <- wb_load(file_name, sheet_name, data_only = FALSE)
# Find placeholder position
data <- read_xlsx(file_name, sheet = sheet_name, skip_empty_rows = FALSE, skip_empty_cols = FALSE)
placeholder <- "##PLACEHOLDER##"
position <- which(data == placeholder, arr.ind = TRUE)
start_row <- position[1,'row'] + 1
start_col <- position[1, 'col']
# Test Table
test_table <- data.frame(
Colum1 = c("TestValue1", "TestValue2", "TestValue3"),
Colum2 = c(10, 20, 30)
)
# Add Data to Workbook
wb <- wb_add_data_table(wb, x = test_table, start_col = start_col, start_row = start_row) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
@joshuasami , since your workbook already contains values or formulas below, the simplest approach would be to write the output into another file and copy it over manually in a spreadsheet formula. I have explained for instance here why |
Beta Was this translation helpful? Give feedback.
@joshuasami , since your workbook already contains values or formulas below, the simplest approach would be to write the output into another file and copy it over manually in a spreadsheet formula.
I have explained for instance here why
openxlsx2
has no function to insert columns or rows.