Learn R Programming

xlsx (version 0.1.1)

Cell: Functions to manipulate cells.

Description

Functions to manipulate cells.

Usage

createCell(row, colIndex=1:5)

getCells(row, simplify=TRUE)

setCellValue(cell, value, richTextString=FALSE)

getCellValue(cell, keepFormulas=FALSE)

Arguments

row
a list of row objects. See Row.
colIndex
a numeric vector specifying the index of columns to create.
simplify
a logical value. If TRUE, the result will be unlisted.
value
an R variable of length one.
richTextString
a logical value indicating if the value should be inserted into the Excel cell as rich text.
keepFormulas
a logical value. If TRUE the formulas will be returned as characters instead of being explicitly evaluated.
cell
an object of type Cell.

Value

  • createCell creates a matrix of lists, each element of the list being a java object reference to an object of type Cell representing an empty cell. The dimnames of this matrix are taken from the names of the rows and the colIndex variable. getCells returns a list of java object references for all the cells in the row. getCellValue returns the value in the cell as an R object. Type conversions are done behind the scene. This function is not vectorized.

Details

setCellValue writes the content of an R variable into the cell. Date and POSIXct objects are passed in as numerical values. To format them as dates in Excel see CellStyle. This function is not vectorized.

See Also

To format cells, see CellStyle.

Examples

Run this code
file <- system.file("tests", "test_import.xlsx", package = "xlsx")

wb <- loadWorkbook(file)  
sheets <- getSheets(wb)

sheet <- sheets[[2]]      # get second sheet
rows  <- getRows(sheet)   # get all the rows

cells <- getCells(rows)   # returns all non empty cells

values <- lapply(cells, getCellValue) # extract the values

Run the code above in your browser using DataLab