How to use openxlsx library to Generate multiple xlsx-output in R In Excel
The openxlsx package in R can be downloaded and installed into the R environment and is used to perform read/write and format transactions conveniently. It can be used to write data frames or Tibbles onto Excel sheets. It can also be used to style the worksheets.
install.packages("openxlsx")
The data frames that are created can be simultaneously mapped to the sheets of the Excel workbook, using the list method. An associative mapping of the sheet-name pointing to the data frame value is created. This creates a list of data frames.
list(key = value, .. )
Arguments :
keyvalue – The key-value pairs indicative of the sheet name and the corresponding data frame.
Then, the write.xlsx() method is then invoked in order to write the entire list of data frames to the specified file path.
R
# installing the required libraries library (openxlsx) # mapping the data frames onto the list data_frames <- list ( "Sheet 1" = df1, "Sheet 2" = df2, "Sheet 3" = df3) # writing the list of data frames onto the xlsx file write.xlsx (data_frames, file = "/Users/mallikagupta/Desktop/multiple_outputs.xlsx" ) |
Output:
Export Dataframes to Multiple Excel Sheets in R
An excel workbook is used to contain tabular information stored within a cell-like structure. Every excel workbook in R contains multiple sheets to contain the data belonging to the same domain information. The excel sheet can contain columns belonging to different data types. The Excel files can be created from data frames using R.
Contact Us