Adds a table of contents to an .xlsx (Excel
) file
Source: R/create_table_of_contents.R
create_table_of_contents.Rd
This function adds a table of contents to an Excel
file by reading the
information from the Excel
sheet in, and then using that data to create
the table of contents. It guesses what the information is, see details below.
Usage
create_table_of_contents(
file,
title = NA_character_,
overwrite = TRUE,
pull_titles = TRUE,
TOC_sheet_name = "Table of Contents"
)
Arguments
- file
the file name.
- title
the title for the table.
- overwrite
logical. When
TRUE
overwrite the file, ifFALSE
it will not overwrite the file.- pull_titles
when
TRUE
take the titles from theExcel
sheets, and add them to the description in the TOC_sheet_name.- TOC_sheet_name
string. the sheet name for the table of contents.
Details
This function uses the sheet names to create the table of contents. For the titles it pulls the text that is the position A1 in each of the sheets. It chooses this as this is the default location of titles when you write a xlr_table with write_xlsx.
Examples
library(xlr)
library(openxlsx)
table_list <- list("Sheet name 1" = mtcars,
"Sheet name 2" = mtcars)
output_file <- "example_file.xlsx"
# using write xlsx we create an `Excel` document
# You could use xlr::write_xlsx to create a table of
# contents automatically.
write.xlsx(table_list,
output_file)
# Now add the table of contents to the existing file
create_table_of_contents(output_file,
"A workbook with example tables",
# it only makes sense to pull titles when
# the first cell has a text description
pull_titles = FALSE)