How to write in a specific Row or column Using write.xlsx in R Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report The Excel File contains cells where the data can be stored in them. To deal with Excel Files in R programming Language we have a package named xlsx. Using the write.xlsx() function present in that package we are going to insert data into an excel file. We are going to insert data at a specified row and column in R. So, As we know excel sheet is a Two-dimensional data set so we are going to first create a matrix with the required number of rows and columns later we are going to update the data at specified positions and simply insert that matrix into excel file. Syntax: write.xlsx(df, file, sheetName, col.names, row.names, append, showNA, password) df - data frame or a 2D matrix object which is to be inserted into excel filefile - the path to the output excel file is specified herecol.names - logical value indicating if the column names of the data frame are to be written in the filerow.names - logical value indicating if the row names of the data frame are to be written in the fileWriting a matrix data to Excel using Step 1: First, we need to install and load the required package(xlsx) R install.packages("xlsx") library(xlsx) Step 2: Next, we need to create an empty matrix with the required number of rows and columns here we will consider a 10 x 10 matrix. R # Creation of Empty Matrix m<-matrix('', nrow=10, ncol=10) m Output: Step 3: Later on we need to update the matrix where we want to insert data in an excel file. Let us consider if we want to insert data in the cell which is present at the 4th row and 4th column which is D4 then we have to update the matrix at the (4, 4) position of it. R # Updating value present at fourth row and fourth column m[4,4]<-"Geeks" m[5,5]<-"For" m[6,6]<-"Geeks" m Output: Step 4: Finally, we are going to insert this matrix into an excel file using the write.xlsx() function R # Inserting matrix into an excel file using write.xlsx xlsx::write.xlsx(m, "C:\\Users\\Downloads\\Sample_excel.xlsx", col.names=FALSE, row.names=FALSE) Output: Comment More infoAdvertise with us Next Article How to write to CSV in R without index ? S sri06harsha Follow Improve Article Tags : Technical Scripter R Language Technical Scripter 2022 Similar Reads How to read a XLSX file with multiple Sheets in R? In this article, we are going to see how to read an XLSX file with multiple Sheets in R Language. There are various external packages in R used to read XLSX files with multiple sheets. File Used: Method 1: Using readxl package The readxl package in R is used to import and read Excel workbooks in R, 5 min read How to Remove a Column using Dplyr package in R In this article, we are going to remove a column(s) in the R programming language using dplyr library. Dataset in use: Remove column using column nameHere we will use select() method to select and remove column by its name. Syntax: select(dataframe,-column_name) Here, dataframe is the input datafram 3 min read How to Color Cells with write.xlsx The xlsx package in R provides functions that can be used to read, write and format excel files. In this article, we will look at one such use of the xlsx package to format and basically color the cells of an XLSX file using the XLSX package and R Programming Language. Coloring Cells using XLSX Pack 5 min read How to read Excel file and select specific rows and columns in R? In this article, we will discuss how to read an Excel file and select specific rows and columns from it using R Programming Language. File Used: To read an Excel file into R we have to pass its path as an argument to read_excel() function readxl library. Syntax: read_excel(path) To select a specific 2 min read How to write to CSV in R without index ? We know that when we write some data from DataFrame to CSV file then a column is automatically created for indexing. We can remove it by some modifications. So, in this article, we are going to see how to write CSV in R without index. To write to csv file write.csv() is used. Syntax: write.csv(data, 2 min read How to Freeze the Top Row and the First Column Using XlsxWriter? When working with Excel files, itâs common to want to keep certain rows and columns visible while scrolling through large datasets. Freezing panes in Excel allows us to do just that. Developed by John McNamara, XlsxWriter uses the Open XML standards and offers many of the native features of Excel, i 4 min read Like