openxlsx2 icon indicating copy to clipboard operation
openxlsx2 copied to clipboard

namedRegion and table names clash

Open JanMarvin opened this issue 2 years ago • 0 comments

Even though they are handled separately in openxml, it is impossible to have identical names for tables and regions (our name for definedName). A check should be added, when creating a table or a defined name. Maybe something like wb_named_region_validate() that breaks if either name is found. It's a bit unfortunate that the table names are burried in wb$tables$tab_xml.

wb <- wb_workbook()
# add a table to the sheet
wb$add_worksheet("Sheet 1")
wb$add_data_table(sheet = "Sheet 1", x = iris, tableName = "iris")
# add a named region to the sheet: names clash the file is broken
wb$add_worksheet("Sheet 2")
wb$add_named_region(
  sheet = 2,
  name = "iris",
  rows = seq_len(nrow(iris) + 1),
  cols = seq_along(iris)
)

JanMarvin avatar May 22 '22 11:05 JanMarvin