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

383,398

Version

4.2.9

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Jan Marvin Garbuszus

Last Published

September 2nd, 2026

Functions in openxlsx (4.2.9)

getCellRefs

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

Create a new Workbook object
dataValidation

Add data validation to cells
createStyle

Create a cell style
freezePane

Freeze a worksheet pane
deleteDataColumn

Deletes a whole column from a workbook
getDateOrigin

Get the date origin an xlsx file is using
deleteData

Delete cell data
getBaseFont

Return the workbook default font
get_worksheet_entries

Get entries from workbook worksheet
getStyles

Returns a list of all styles in the workbook
groupRows

Group Rows
getNamedRegions

Get named regions
insertPlot

Insert the current plot into a worksheet
groupColumns

Group columns
if_null_then

If NULL then ...
getTables

List Excel tables in a workbook
getSheetNames

Get names of worksheets
insertImage

Insert an image into a worksheet
modifyBaseFont

Modify the default font
makeHyperlinkString

create Excel hyperlink string
mergeCells

Merge cells within a worksheet
names

get or set worksheet names
loadWorkbook

Load an existing .xlsx file
openXL

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

Convert integer to Excel column
openxlsx_options

openxlsx Options
openxlsx

xlsx reading, writing and editing.
openxlsxFontSizeLookupTable

Font Size Lookup tables
protectWorkbook

Protect a workbook from modifications
readWorkbook

Read from an Excel file or Workbook object
read.xlsx

Read from an Excel file or Workbook object
removeComment

Remove a comment from a cell
removeCellMerge

Create a new Workbook object
removeColWidths

Remove column widths from a worksheet
protectWorksheet

Protect a worksheet from modifications
pageSetup

Set page margins, orientation and print scaling
pageBreak

add a page break to a worksheet
removeFilter

Remove a worksheet filter
setColWidths

Set worksheet column widths
setHeaderFooter

Set document headers and footers
replaceStyle

Replace an existing cell style
setFooter

Set footer for all worksheets
saveWorkbook

save Workbook to file
removeTable

Remove an Excel table in a workbook
setHeader

Set header for all worksheets
removeRowHeights

Remove custom row heights from a worksheet
renameWorksheet

Rename a worksheet
setRowHeights

Set worksheet row heights
removeWorksheet

Remove a worksheet from a workbook
ungroupRows

Ungroup Rows
sheetVisible

Get worksheet visible state.
setLastModifiedBy

Set the author who modified the file last.
setWindowSize

Set and Get Window Size for xlsx file
ungroupColumns

Ungroup Columns
sheets

Returns names of worksheets.
sheetVisibility

Get/set worksheet visible state
showGridLines

Set worksheet gridlines to show or hide.
temp_xlsx

helper function to create tempory directory for testing purpose
worksheetOrder

Order of worksheets in xlsx file
writeData

Write an object to a worksheet
writeDataTable

Write to a worksheet as an Excel table
write.xlsx

write data to an xlsx file
writeFormula

Write a character vector as an Excel Formula
writeComment

write a cell comment
addWorksheet

Add a worksheet to a workbook
addStyle

Add a style to a set of cells
as.character.formula

as.character.formula()
auto_heights

Compute optimal row heights
addFilter

Add column filters
activeSheet

Get/set active sheet of the workbook
addCreator

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

Check equality of workbooks
createNamedRegion

Create / delete a named region.
as_POSIXct_utc

Convert to POSIXct with timezone UTC
convertToDateTime

Convert from excel time number to R POSIXct type.
conditionalFormat

Add conditional formatting to cells
cloneWorksheet

Clone a worksheet to a workbook
copyWorkbook

Copy a Workbook object.
convertToDate

Convert from excel date number to R Date type
col2int

Convert Excel column to integer
conditionalFormatting

Add conditional formatting to cells
convertFromExcelRef

Convert excel column name to integer index
createComment

create a Comment object
buildWorkbook

Build Workbook
getCreators

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