Learn R Programming

xlsx (version 0.1.1)

xlsx-package: Read, write, format Excel 2007 (xlsx) files

Description

The xlsx package gives programatic control of Excel 2007 files using R. A high level API allows the user to read a sheet of an xlsx document into a data.frame and write a data.frame to an xlsx file. Lower level functionality permits the direct manipulation of sheets, rows and cells. For example, the user has control to set colors, fonts, data formats, add borders, hide/unhide sheets, add/remove rows, add/remove sheets, etc. Behind the scenes, the xlsx package uses a java library from the Apache project, http://poi.apache.org/index.html. This Apache project provides a Java API to Microsoft Documents (Excel, Word, PowerPoint, Outlook, Visio, etc.) By using the rJava package that links Rand Java, we can piggyback on the excellent work already done by the folks at the Apache project and provide this functionality in R. The xlsx package uses only a subset of the Apache POI project, namely the one dealing with Excel 2007 files. All the necessary jar files are kept in package xlsxjars that is imported by package xlsx. A package with similar functionality to xlsx is maintained by Duncan Temple Lang at http://www.omegahat.org/RExcelXML/. The approach taken there is to directly process the underlying XML files. You should check it out as that approach may be superior in certain cases. For example, the package xlsx has a bigger memory footprint at start-up. A collection of tests that can be used as examples are located in folder /tests/.

Patches with bug fixes and improvements are welcome. The development version of this package is hosted on R-Forge at http://r-forge.r-project.org/projects/xlsx/. NOTE: You may need to add to your PATH variable the location of your JVM (e.g. C:/Program Files/Java/jre6/bin/client) to get rJava working.

Arguments

Details

ll{ Package: xlsx Type: Package Version: 0.1.1 Date: 2010-01-01 License: GPL-3 }

References

Apache POI project for Microsoft Excel format: http://poi.apache.org/spreadsheet/index.html. The Java Doc detailing the classes: http://poi.apache.org/apidocs/index.html. This can be useful if you are looking for something that is not exposed in R as it may be available on the Java side. Inspecting the source code for some the the Rfunctions in this package can show you how to do it (even if you are java shy).

See Also

Workbook for ways to work with Workbook objects.

Examples

Run this code
require(xlsx)

# example of reading xlsx sheets
file <- system.file("tests", "test_import.xlsx", package = "xlsx")
res <- read.xlsx(file, 2)  # read the second sheet

# example of writing xlsx sheets
file <- tempfile()
write.xls(USArrests, file=file)

Run the code above in your browser using DataLab