Learn R Programming

WriteXLS (version 1.5.0)

WriteXLS: Cross-platform Perl based R function to create Excel 2003 (XLS) files

Description

Writes one or more R data frames to an Excel file

Usage

WriteXLS(x, ExcelFileName = "R.xls", perl = "perl", verbose = FALSE)

Arguments

x
A character vector containing the names of one or more R data frames to be exported to the Excel file.
ExcelFileName
The name of the Excel file to be created. Must be a valid Excel filename. May include an existing path.
perl
Name of the perl executable to be called.
verbose
Output step-by-step status messages during the creation of the Excel file. Default is FALSE.

Value

  • None

Details

This function takes a character vector containing the names of one or more R data frames and writes them to an Excel 2003 spreadsheet file. Each data frame will be written to a separate worksheet in the Excel file. Each worksheet will be named using the name of the data frame (up to the first 31 characters, which is an Excel limitation). It is therefore possible that if two data frames have the same name up to the 31st character, the corresponding worksheets in the Excel file will have the same name.

The data frame column names will be exported "as is" and will be the first row in the corresponding worksheet.

The data frame row names will NOT be exported.

UTF-8 encoded content in the data frame should be properly exported using the Perl Encode module by default.

There is an intermediate step, where the R data frames are first written to CSV files using write.table before being written to the Excel file. tempdir is used to determine the current R session temporary directory and a new sub-directory called "WriteXLS" will be created there. The CSV files will be written to that directory and both the files and the directory will be deleted prior to the function terminating normally using on.exit. It is possible that these will remain in place if this function terminates abnormally or is aborted prior to completion.

All of the CSV files will be created prior to the creation of the Excel file as the Perl script will loop over them as part of the process. Thus, sufficient free disk space must be available for these files and the Excel file at the same time.

References

Spreadsheet::WriteExcel Perl Module http://search.cpan.org/dist/Spreadsheet-WriteExcel

Excel 2003 Specifications and Limitations http://office.microsoft.com/en-us/excel/HP051992911033.aspx

For Perl Unicode Issues http://www.ahinea.com/en/tech/perl-unicode-struggle.html

See Also

write.table

Examples

Run this code
# Examples using built-in data frames 
  WriteXLS("iris", "iris.xls")

  WriteXLS(c("iris", "infert", "esoph"), "Example.xls")

  # Clean up and delete XLS files
  unlink("iris.xls")
  unlink("Example.xls")

Run the code above in your browser using DataLab