loadWorkbook: Loading Microsoft Excel workbooks

Description Usage Arguments Value Note Author(s) References See Also Examples

View source: R/loadWorkbook.R

Description

Loads or creates a Microsoft Excel workbook for further manipulation.

Usage

1
loadWorkbook(filename, create = FALSE, password = NULL)

Arguments

filename

Filename (absolute or relative) of Excel workbook to be loaded. Supported are Excel '97 (*.xls) and OOXML (Excel 2007+, *.xlsx) file formats. Paths are expanded using path.expand.

create

Specifies if the file should be created if it does not already exist (default is FALSE). Note that create = TRUE has no effect if the specified file exists, i.e. an existing file is loaded and not being recreated if create = TRUE.

password

Password to use when opening password protected files. The default NULL means no password is being used. This argument is ignored when creating new files using create = TRUE.

Value

Returns a workbook object for further manipulation.

Note

loadWorkbook is basically just a shortcut form of new("workbook", filename, create) with some additional error checking. As such it is the preferred way of creating workbook instances.

Author(s)

Martin Studer
Mirai Solutions GmbH https://mirai-solutions.ch

References

Wikipedia: Office Open XML
https://en.wikipedia.org/wiki/Office_Open_XML

See Also

workbook, saveWorkbook

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
## Not run: 
# Load existing demo Excel file 'mtcars.xlsx' from the XLConnect package
wb.mtcars <- loadWorkbook(system.file("demoFiles/mtcars.xlsx", 
                          package = "XLConnect"))

# Create new workbook
wb.new <- loadWorkbook("myNewExcelFile.xlsx", create = TRUE)

# NOTE: The above statement does not write the file to disk! 
# saveWorkbook(wb.new) would need to be called in order to write/save 
# the file to disk!

# clean up 
file.remove("myNewExcelFile.xlsx")

## End(Not run)

XLConnect documentation built on Oct. 1, 2021, 5:06 p.m.