Learn R Programming

excel.link (version 0.9.4)

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)
xl.workbook.activate(xl.workbook.name)
xl.workbooks()
xl.workbook.save(filename, password = NULL)
xl.workbook.close(xl.workbook.name = NULL)

Arguments

filename
character. Excel workbook filename.
password
character. Password for password-protected workbook.
xl.workbook.name
character. Excel workbook name.

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.

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
## Not run: 
# ## 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")
# ## End(Not run)

Run the code above in your browser using DataLab