Learn R Programming

excel.link (version 0.9.13)

xl.workbook.add: Basic operations with Excel workbooks

Description

Basic operations with Excel workbooks

Usage

xl.workbook.add(filename = NULL)

xl.workbook.open(filename, password = NULL, write.res.password = NULL)

xl.workbook.activate(xl.workbook.name)

xl.workbooks(full.names = FALSE)

xl.workbook.save( filename, password = NULL, write.res.password = NULL, file.format = xl.constants$xlOpenXMLWorkbook )

xl.workbook.close(xl.workbook.name = NULL)

Value

  • xl.workbook.add/xl.workbook.open/xl.workbook.activate invisibly return name of created/open/activated workbook.

  • xl.workbooks returns character vector of open workbooks.

  • xl.workbook.save invisibly returns path to the saved workbook.

  • xl.workbook.close invisibly returns NULL.

Arguments

filename

character. Excel workbook filename.

password

character. Password for password-protected workbook.

write.res.password

character. Second password for editing workbook.

xl.workbook.name

character. Excel workbook name.

full.names

logical. Should we return full path to the workbook? FALSE, by default.

file.format

integer. Excel file format. By default it is xl.constants$xlOpenXMLWorkbook. You can use xl.constants$xlOpenXMLWorkbookMacroEnabled for workbooks with macros (*.xlsm) or xl.constants$xlExcel12 for binary workbook (.xlsb).

Details

  • xl.workbook.add adds new workbook and invisibly returns name of this newly created workbook. Added workbook become active. If filename argument is provided then Excel workbook filename will be used as template.

  • xl.workbook.activate activates workbook with given name. If workbook with this name doesn't exist error will be generated.

  • xl.workbook.save saves active workbook. If only filename submitted it saves in the working directory. If name of workbook is omitted than new workbook is saved under its default name in the current working directory. It doesn't prompt about overwriting if file already exists.

  • xl.workbook.close closes workbook with given name. If name isn't submitted it closed active workbook. It doesn't prompt about saving so if you don't save changes before closing all changes will be lost.

See Also

xl.sheets, xl.read.file, xl.save.file

Examples

Run this code
if (FALSE) {
## senseless actions
data(iris)
data(cars)
xl.workbook.add()
xlrc[a1] = iris
xl.workbook.save("iris.xlsx")
xl.workbook.add()
xlrc[a1] = cars
xl.workbook.save("cars.xlsx")
xl.workbook.activate("iris")
xl.workbook.close("cars")
xl.workbook.open("cars.xlsx")
xl.workbooks()
for (wb in xl.workbooks()) xl.workbook.close(wb)
unlink("iris.xlsx")
unlink("cars.xlsx")

# password-protected workbook
data(iris) 
xl.workbook.add()
xlrc[a1] = iris
xl.workbook.save("iris.xlsx", password = "my_password")
xl.workbook.close()
xl.workbook.open("iris.xlsx", password = "my_password")
xl.workbook.close()
unlink("iris.xlsx")
}

Run the code above in your browser using DataLab