Learn R Programming

openxlsx

This R package simplifies the creation of .xlsx files by providing a high level interface to writing, styling and editing worksheets. Through the use of Rcpp, read/write times are comparable to the xlsx and XLConnect packages with the added benefit of removing the dependency on Java.

Note: openxlsx is no longer under active development. The package is maintained, and CRAN warnings will be fixed, but non-critical issues will not be addressed unless accompanied by a pull request. Packages that depend on openxlsx do not need to take any action, but for new developments, users are encouraged to use alternatives like readxl, writexl, or openxlsx2. The first two packages provide support for reading and writing .xlsx files. The latter package is a modern reinterpretation of openxlsx and provides similar functions to modify worksheets. However, it is not a drop-in replacement, so you may want to consult resources like the update vignette.

Installation

Stable version

Current stable version is available on CRAN via

install.packages("openxlsx", dependencies = TRUE)

Development version

install.packages(c("Rcpp", "remotes"), dependencies = TRUE)
remotes::install_github("ycphs/openxlsx")

Example

Explore the package with a simple example:

library(openxlsx)

# Create a new workbook and add a sheet
wb <- createWorkbook()
addWorksheet(wb, "Sheet 1")

# Write data to the sheet
writeData(wb, "Sheet 1", mtcars)

# Save the workbook
saveWorkbook(wb, "my_mtcars.xlsx", overwrite = TRUE)

Bug/feature request

Please let us know which version of openxlsx you are using when posting bug reports.

packageVersion("openxlsx")

News

You can find the NEWS file here.

Copy Link

Version

Install

install.packages('openxlsx')

Monthly Downloads

418,074

Version

4.2.8

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Jan Marvin Garbuszus

Last Published

January 25th, 2025

Functions in openxlsx (4.2.8)

dataValidation

Add data validation to cells
deleteData

Delete cell data
getCellRefs

Return excel cell coordinates from (x,y) coordinates
getBaseFont

Return the workbook default font
getStyles

Returns a list of all styles in the workbook
getTables

List Excel tables in a workbook
groupRows

Group Rows
insertImage

Insert an image into a worksheet
if_null_then

If NULL then ...
getCreators

Get the names of the authors from the meta data of the file.
insertPlot

Insert the current plot into a worksheet
convertToDateTime

Convert from excel time number to R POSIXct type.
getDateOrigin

Get the date origin an xlsx file is using
makeHyperlinkString

create Excel hyperlink string
mergeCells

Merge cells within a worksheet
deleteDataColumn

Deletes a whole column from a workbook
freezePane

Freeze a worksheet pane
protectWorkbook

Protect a workbook from modifications
modifyBaseFont

Modify the default font
get_worksheet_entries

Get entries from workbook worksheet
removeCellMerge

Create a new Workbook object
names

get or set worksheet names
groupColumns

Group columns
openxlsx

xlsx reading, writing and editing.
openXL

Open a Microsoft Excel file (xls/xlsx) or an openxlsx Workbook
pageBreak

add a page break to a worksheet
protectWorksheet

Protect a worksheet from modifications
pageSetup

Set page margins, orientation and print scaling
int2col

Convert integer to Excel column
read.xlsx

Read from an Excel file or Workbook object
removeRowHeights

Remove custom row heights from a worksheet
readWorkbook

Read from an Excel file or Workbook object
removeTable

Remove an Excel table in a workbook
saveWorkbook

save Workbook to file
sheets

Returns names of worksheets.
sheetVisible

Get worksheet visible state.
replaceStyle

Replace an existing cell style
loadWorkbook

Load an existing .xlsx file
write.xlsx

write data to an xlsx file
worksheetOrder

Order of worksheets in xlsx file
setColWidths

Set worksheet column widths
setFooter

Set footer for all worksheets
removeWorksheet

Remove a worksheet from a workbook
removeColWidths

Remove column widths from a worksheet
showGridLines

Set worksheet gridlines to show or hide.
setWindowSize

Set and Get Window Size for xlsx file
sheetVisibility

Get/set worksheet visible state
createStyle

Create a cell style
writeDataTable

Write to a worksheet as an Excel table
renameWorksheet

Rename a worksheet
createWorkbook

Create a new Workbook object
setLastModifiedBy

Set the author who modified the file last.
setRowHeights

Set worksheet row heights
getSheetNames

Get names of worksheets
getNamedRegions

Get named regions
writeComment

write a cell comment
temp_xlsx

helper function to create tempory directory for testing purpose
writeFormula

Write a character vector as an Excel Formula
setHeaderFooter

Set document headers and footers
removeComment

Remove a comment from a cell
setHeader

Set header for all worksheets
openxlsxFontSizeLookupTable

Font Size Lookup tables
removeFilter

Remove a worksheet filter
ungroupColumns

Ungroup Columns
ungroupRows

Ungroup Rows
openxlsx_options

openxlsx Options
writeData

Write an object to a worksheet
addCreator

Add another author to the meta data of the file.
all.equal

Check equality of workbooks
addStyle

Add a style to a set of cells
addWorksheet

Add a worksheet to a workbook
createNamedRegion

Create / delete a named region.
as_POSIXct_utc

Convert to POSIXct with timezone UTC
auto_heights

Compute optimal row heights
as.character.formula

as.character.formula()
addFilter

Add column filters
activeSheet

Get/set active sheet of the workbook
copyWorkbook

Copy a Workbook object.
col2int

Convert Excel column to integer
cloneWorksheet

Clone a worksheet to a workbook
createComment

create a Comment object
conditionalFormatting

Add conditional formatting to cells
buildWorkbook

Build Workbook
conditionalFormat

Add conditional formatting to cells
convertToDate

Convert from excel date number to R Date type
convertFromExcelRef

Convert excel column name to integer index