Showing posts with label Excel. Show all posts
Showing posts with label Excel. Show all posts

Monday, January 19, 2015

Read part of an Excel sheet into an R data.frame

Documentation of the read.xlsx function: 
read.xlsx(file, sheetIndex, sheetName=NULL, rowIndex=NULL,  startRow=NULL, endRow=NULL, colIndex=NULL,  as.data.frame=TRUE, header=TRUE, colClasses=NA,  keepFormulas=FALSE, encoding="unknown", ...)
Returns a data.frame.
Example of use:
dtf <- file="filename,<!-----" read.xlsx="">
    sheetName = sheetname,
    rowIndex = 2:10, 
    colIndex = 5:20)

Thursday, August 22, 2013

Export Excel files with multiple sheets from R using XLSX

require(xlsx)
wb = createWorkbook()

# Create a first sheet
sheet  = createSheet(wb, sheetName="NewSheet.1")
rows = createRow(sheet, rowIndex=1:2)
cells = createCell(rows, colIndex=1:8)
setCellValue(cells[[1,1]],"Text")
setCellValue(cells[[1,2]],-0.1)
setCellValue(cells[[1,3]],"=B1+1")

# Create another sheet
sheet  = createSheet(wb, sheetName="NewSheet.2")
rows = createRow(sheet, rowIndex=1:2)
cells = createCell(rows, colIndex=1:8)
setCellValue(cells[[1,1]],"Text")

# Save Excel file and show me the names of the sheets that have been created
saveWorkbook(wb, "trying out.xlsx")
names(getSheets(wb) )

XLSX Package on CRAN

XLSX is based on the Apache  POI project. I still need to figure out  how to evaluate formulas in the Excel file. There may be some help at the Apache POI formula evaluation page.

Friday, March 08, 2013

Installing RExcel

I wanted to install RExcel from the cran package.
The think is that you need this packages installed before:
  • rscproxy 2.0-5
  • rcom 2.2-5
For the next install, If I need to reinstall RExcel for someone else, I think I'll try using this RandFriends package. Which installs R together with the required extension for running RExcel.