workbook-class {XLConnect}R Documentation

Class "workbook"

Description

This is XLConnect's main entity representing a Microsoft Excel workbook. S4 objects of this class and corresponding methods are used to manipulate the underlying Excel workbook instances.

Objects from the Class

Objects can be created by calls of the form loadWorkbook(filename, create). This is a shortcut form of new("workbook", filename, create) with some additional error checking.

Slots

filename:

Object of class character which represents the filename of the underlying Microsoft Excel workbook.

jobj:

Object of class jobjRef (see package rJava) which represents a Java object reference that is used in the back-end to manipulate the underlying Excel workbook instance.

These slots should not be accessed directly in user code. workbook objects should only be manipulated via the corresponding methods.

Note

XLConnect supports both Excel 97-2003 (*.xls) and OOXML (Excel 2007+, *.xlsx) file formats.

A workbook's underlying Excel file is not saved (or being created in case the file did not exist and create = TRUE has been specified) unless the saveWorkbook method has been called on the object. This provides more flexibility to the user to decide when changes are saved and also provides better performance in that several changes can be written in one go (normally at the end, rather than after every operation causing the file to be rewritten again completely each time). This is due to the fact that workbooks are manipulated in-memory and are only written to disk with specifically calling saveWorkbook.

Author(s)

Martin Studer
Mirai Solutions GmbH http://www.mirai-solutions.com

References

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

See Also

loadWorkbook, saveWorkbook

Examples

# Create a new workbook 'myWorkbook.xlsx' 
# (assuming the file to not exist already)
wb <- loadWorkbook("myWorkbook.xlsx", create = TRUE)

# Create a worksheet called 'mtcars'
createSheet(wb, name = "mtcars")

# Write built-in dataset 'mtcars' to sheet 'mtcars' created above
writeWorksheet(wb, mtcars, sheet = "mtcars")

# Save workbook - this actually writes the file 'myWorkbook.xlsx' to disk
saveWorkbook(wb)

[Package XLConnect version 0.2-7 Index]