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

429,649

Version

4.2.8.1

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Jan Marvin Garbuszus

Last Published

October 31st, 2025

Functions in openxlsx (4.2.8.1)

getCreators

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

Get the date origin an xlsx file is using
freezePane

Freeze a worksheet pane
createStyle

Create a cell style
createWorkbook

Create a new Workbook object
conditionalFormat

Add conditional formatting to cells
col2int

Convert Excel column to integer
dataValidation

Add data validation to cells
insertImage

Insert an image into a worksheet
deleteDataColumn

Deletes a whole column from a workbook
insertPlot

Insert the current plot into a worksheet
deleteData

Delete cell data
getStyles

Returns a list of all styles in the workbook
getCellRefs

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

Get entries from workbook worksheet
getSheetNames

Get names of worksheets
groupColumns

Group columns
getBaseFont

Return the workbook default font
openXL

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

xlsx reading, writing and editing.
int2col

Convert integer to Excel column
getNamedRegions

Get named regions
mergeCells

Merge cells within a worksheet
makeHyperlinkString

create Excel hyperlink string
openxlsxFontSizeLookupTable

Font Size Lookup tables
openxlsx_options

openxlsx Options
getTables

List Excel tables in a workbook
removeFilter

Remove a worksheet filter
removeComment

Remove a comment from a cell
loadWorkbook

Load an existing .xlsx file
readWorkbook

Read from an Excel file or Workbook object
read.xlsx

Read from an Excel file or Workbook object
setFooter

Set footer for all worksheets
sheetVisible

Get worksheet visible state.
pageSetup

Set page margins, orientation and print scaling
pageBreak

add a page break to a worksheet
removeWorksheet

Remove a worksheet from a workbook
setColWidths

Set worksheet column widths
if_null_then

If NULL then ...
groupRows

Group Rows
removeColWidths

Remove column widths from a worksheet
removeCellMerge

Create a new Workbook object
sheets

Returns names of worksheets.
modifyBaseFont

Modify the default font
names

get or set worksheet names
setHeader

Set header for all worksheets
setRowHeights

Set worksheet row heights
setLastModifiedBy

Set the author who modified the file last.
removeRowHeights

Remove custom row heights from a worksheet
removeTable

Remove an Excel table in a workbook
replaceStyle

Replace an existing cell style
saveWorkbook

save Workbook to file
setHeaderFooter

Set document headers and footers
ungroupRows

Ungroup Rows
ungroupColumns

Ungroup Columns
setWindowSize

Set and Get Window Size for xlsx file
protectWorksheet

Protect a worksheet from modifications
protectWorkbook

Protect a workbook from modifications
sheetVisibility

Get/set worksheet visible state
writeComment

write a cell comment
writeDataTable

Write to a worksheet as an Excel table
writeData

Write an object to a worksheet
writeFormula

Write a character vector as an Excel Formula
renameWorksheet

Rename a worksheet
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
write.xlsx

write data to an xlsx file
addFilter

Add column filters
addStyle

Add a style to a set of cells
all.equal

Check equality of workbooks
auto_heights

Compute optimal row heights
addCreator

Add another author to the meta data of the file.
addWorksheet

Add a worksheet to a workbook
as_POSIXct_utc

Convert to POSIXct with timezone UTC
as.character.formula

as.character.formula()
activeSheet

Get/set active sheet of the workbook
createNamedRegion

Create / delete a named region.
createComment

create a Comment object
copyWorkbook

Copy a Workbook object.
convertToDate

Convert from excel date number to R Date type
buildWorkbook

Build Workbook
cloneWorksheet

Clone a worksheet to a workbook
convertFromExcelRef

Convert excel column name to integer index
conditionalFormatting

Add conditional formatting to cells
convertToDateTime

Convert from excel time number to R POSIXct type.