saveWorkbook-methods
Saving Microsoft Excel workbooks
Saves a '>workbook
to the corresponding Excel file. This method actually writes the '>workbook
object to disk.
Usage
# S4 method for workbook,missing
saveWorkbook(object,file)
# S4 method for workbook,character
saveWorkbook(object,file)
Arguments
- object
- file
The file to which to save the
'>workbook
("save as"). If not specified (missing), the workbook will be saved to the'>workbook
's underlying file which is the file specified inloadWorkbook
(also see the'>workbook
class for more information). Note that due to currently missing functionality in Apache POI, workbooks can only be saved in the same file format - i.e. if the workbooks underlying file format is xls, then thefile
argument may only specify another xls file. Also note that when specifying thefile
argument the'>workbook
's underlying filename changes to reflect the "save as" behavior. Paths are expanded usingpath.expand
.
Details
Note
As already mentioned in the documentation of the
'>workbook
class, 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
.
Further note that calling saveWorkbook
more than once leads to an
exception. This is due to a current issue in the underlying POI libraries.
However, with XLConnect there should be no need to call saveWorkbook
more than once so virtually this is no issue.
See Also
'>workbook
, loadWorkbook
Examples
# NOT RUN {
# Create a new workbook 'saveMe.xlsx'
# (assuming the file to not exist already)
wb <- loadWorkbook("saveMe.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 'saveMe.xlsx' to disk
saveWorkbook(wb)
# }