R: Get named regions

getNamedRegions {openxlsx} | R Documentation

## Get named regions

### Description

Return a vector of named regions in a xlsx file or Workbook object

### Usage

    getNamedRegions(x)

### Arguments

`x` | An xlsx file or Workbook object

### See Also

`createNamedRegion`

### Examples

    ## create named regions
    wb <- createWorkbook()
    addWorksheet(wb, "Sheet 1")

    ## specify region
    writeData(wb, sheet = 1, x = iris, startCol = 1, startRow = 1)
    createNamedRegion(
      wb = wb,
      sheet = 1,
      name = "iris",
      rows = 1:(nrow(iris) + 1),
      cols = 1:ncol(iris)
    )

    ## using writeData 'name' argument to create a named region
    writeData(wb, sheet = 1, x = iris, name = "iris2", startCol = 10)
    ## Not run:
    out_file <- tempfile(fileext = ".xlsx")
    saveWorkbook(wb, out_file, overwrite = TRUE)

    ## see named regions
    getNamedRegions(wb) ## From Workbook object
    getNamedRegions(out_file) ## From xlsx file

    ## read named regions
    df <- read.xlsx(wb, namedRegion = "iris")
    head(df)

    df <- read.xlsx(out_file, namedRegion = "iris2")
    head(df)

    ## End(Not run)

[Package openxlsx version 4.2.4 Index]