IronXL How-Tos Write Excel .NET Write Excel .NET Functions Chaknith Bin Updated:July 28, 2025 Many C# application projects require us to update files and write new data in Excel spreadsheets programmatically. Excel .NET capabilities can sometimes be complicated, but using the IronXL library, this task is quite simple and allows working with Excel spreadsheets in any format. No bulk lines of code, just access to the specific cells and the custom values you assign. Get started with IronXL Start using IronXL in your project today with a free trial. First Step: Start for Free Write Excel .NET Instructions Download the Library for Excel .NET Write values in specific cells Write static values in multiple cells Write dynamic values in cell range Replace cell values in specific row, column, range, and more Access Excel Files Let's start by accessing the Excel file in which we want to write the data. Let's open the Excel file in our project, and then open its specific worksheet using the following code. :path=/static-assets/excel/content-code-examples/how-to/write-excel-net-load-file.cs // Load Excel file in the project WorkBook workBook = WorkBook.Load("path"); ' Load Excel file in the project Dim workBook As WorkBook = WorkBook.Load("path") $vbLabelText $csharpLabel The above will open the specified Excel file. Next, access the worksheet. :path=/static-assets/excel/content-code-examples/how-to/write-excel-net-get-sheet.cs // Open Excel WorkSheet WorkSheet workSheet = workBook.GetWorkSheet("Sheet1"); ' Open Excel WorkSheet Dim workSheet As WorkSheet = workBook.GetWorkSheet("Sheet1") $vbLabelText $csharpLabel The Excel worksheet will open in worksheet and we can use it to write any type of data in the Excel file. Learn more about how to load Excel files and access worksheets in different ways through the examples in the link. Note: Don't forget to add the reference to IronXL in your project and import the library by using using IronXL. Write Value in Specific Cell We can write in an Excel file using many different methods, but the basic approach is using ExcelCell. For this purpose, any cell of the opened Excel worksheet can be accessed and a value written in it as follows: :path=/static-assets/excel/content-code-examples/how-to/write-excel-net-assign-cell.cs workSheet["Cell Address"].Value="Assign the Value"; workSheet("Cell Address").Value="Assign the Value" $vbLabelText $csharpLabel Here's an example of how to use the above function to write in an Excel Cell in our C# project. :path=/static-assets/excel/content-code-examples/how-to/write-excel-net-assign-cell-full.cs using IronXL; // Load Excel file WorkBook workBook = WorkBook.Load("sample.xlsx"); // Open WorkSheet of sample.xlsx WorkSheet workSheet = workBook.GetWorkSheet("Sheet1"); // Access A1 cell and write the value workSheet["A1"].Value = "new value"; // Save changes workBook.SaveAs("sample.xlsx"); Imports IronXL ' Load Excel file Private workBook As WorkBook = WorkBook.Load("sample.xlsx") ' Open WorkSheet of sample.xlsx Private workSheet As WorkSheet = workBook.GetWorkSheet("Sheet1") ' Access A1 cell and write the value Private workSheet("A1").Value = "new value" ' Save changes workBook.SaveAs("sample.xlsx") $vbLabelText $csharpLabel This code will write new value in cell A1 of the worksheet Sheet1 in the Excel file sample.xlsx. In the same way, we can insert values in any cell address of an Excel file. Note: Don't forget to save the Excel file after writing new values in the worksheet, as shown in the example above. Force Assign the Exact Value When setting the Value property, IronXL will try to convert it to its corresponding value type. Sometimes, this evaluation is undesirable since the user wants to force assign the exact value to the cell without conversion. To do this, assign the value as a string. In IronXL, simply use StringValue instead of Value to achieve the same effect. :path=/static-assets/excel/content-code-examples/how-to/write-excel-net-assign-stringvalue.cs // Assign value as string workSheet["A1"].StringValue = "4402-12"; ' Assign value as string workSheet("A1").StringValue = "4402-12" $vbLabelText $csharpLabel Write Static Values in a Range We can write new values in multiple cells, called a range, as follows: // Assign a static value to a range of cells worksheet["B2:C5"].Value = "static value"; // Assign a static value to a range of cells worksheet["B2:C5"].Value = "static value"; ' Assign a static value to a range of cells worksheet("B2:C5").Value = "static value" $vbLabelText $csharpLabel In this way, we specify the range of cells From to To where the data will be written. The new value will be written in all the cells which lie in this range. To understand more about C# Excel Range, check out the examples here. Let's see how to write a range in action using the example below. :path=/static-assets/excel/content-code-examples/how-to/write-excel-net-assign-cell-range-full.cs using IronXL; // Load Excel file WorkBook workBook = WorkBook.Load("sample.xlsx"); // Open WorkSheet of sample.xlsx WorkSheet workSheet = workBook.GetWorkSheet("Sheet1"); // Specify range row wise and write new value workSheet["B2:B9"].Value = "new value"; // Specify range column wise and write new value workSheet["C3:C7"].Value = "new value"; // Save changes workBook.SaveAs("sample.xlsx"); Imports IronXL ' Load Excel file Private workBook As WorkBook = WorkBook.Load("sample.xlsx") ' Open WorkSheet of sample.xlsx Private workSheet As WorkSheet = workBook.GetWorkSheet("Sheet1") ' Specify range row wise and write new value Private workSheet("B2:B9").Value = "new value" ' Specify range column wise and write new value Private workSheet("C3:C7").Value = "new value" ' Save changes workBook.SaveAs("sample.xlsx") $vbLabelText $csharpLabel This code will write new value from B2 to C5 in the worksheet Sheet1 of the Excel file sample.xlsx. It uses static values for the Excel cells. Write Dynamic Values in a Range We can also add dynamic values to a range, as seen below. :path=/static-assets/excel/content-code-examples/how-to/write-excel-net-assign-dynamic-value.cs using IronXL; // Load Excel file WorkBook workBook = WorkBook.Load("sample.xlsx"); // Open WorkSheet of sample.xlsx WorkSheet workSheet = workBook.GetWorkSheet("Sheet1"); // Specify range in which we want to write the values for (int i = 2; i <= 7; i++) { // Write the Dynamic value in one row workSheet["B" + i].Value = "Value" + i; // Write the Dynamic value in another row workSheet["D" + i].Value = "Value" + i; } // Save changes workBook.SaveAs("sample.xlsx"); Imports IronXL ' Load Excel file Private workBook As WorkBook = WorkBook.Load("sample.xlsx") ' Open WorkSheet of sample.xlsx Private workSheet As WorkSheet = workBook.GetWorkSheet("Sheet1") ' Specify range in which we want to write the values For i As Integer = 2 To 7 ' Write the Dynamic value in one row workSheet("B" & i).Value = "Value" & i ' Write the Dynamic value in another row workSheet("D" & i).Value = "Value" & i Next i ' Save changes workBook.SaveAs("sample.xlsx") $vbLabelText $csharpLabel The above code will write dynamic values in columns B from 2 to 7 in the Excel file sample.xlsx. We can see the result of the code on sample.xlsx. Replace Excel Cell Value Using IronXL, we can easily write a new value to replace the old value, using the Replace() function as follows: :path=/static-assets/excel/content-code-examples/how-to/write-excel-net-replace.cs workSheet.Replace("old value", "new value"); workSheet.Replace("old value", "new value") $vbLabelText $csharpLabel The above function will write new value overwriting the old value in the complete Excel worksheet. Replace Cell Value in Specific Row If we want to write a new value only in one specific row, do as follows: :path=/static-assets/excel/content-code-examples/how-to/write-excel-net-replace-row.cs workSheet.Rows[RowIndex].Replace("old value", "new value"); workSheet.Rows(RowIndex).Replace("old value", "new value") $vbLabelText $csharpLabel This will write new value over the old value in only the specified row index. Replace Cell Value in Specific Column Similarly, if we want to write new value over the old value within a specific column, do as follows: :path=/static-assets/excel/content-code-examples/how-to/write-excel-net-replace-column.cs workSheet.Columns[ColumnIndex].Replace("old value", "new Value"); workSheet.Columns(ColumnIndex).Replace("old value", "new Value") $vbLabelText $csharpLabel The above code will write new value to replace the old value, but only in the specified column index. The rest of the worksheet remains the same. Replace Cell Value in Specific Range IronXL also provides a way to write a new value replacing the old value, only in a specified range. :path=/static-assets/excel/content-code-examples/how-to/write-excel-net-replace-range.cs workSheet["From Cell Address : To Cell Address"].Replace("old value", "new value"); workSheet("From Cell Address : To Cell Address").Replace("old value", "new value") $vbLabelText $csharpLabel This will write new value above old value, just in the cells which lie in the specified range. Let's see the example of how to use all of the above functions to write new values to replace old values in an Excel worksheet. Example of all Functions :path=/static-assets/excel/content-code-examples/how-to/write-excel-net-replace-full.cs using IronXL; WorkBook workBook = WorkBook.Load("sample.xlsx"); WorkSheet workSheet = workBook.GetWorkSheet("Sheet1"); // Write new above old in complete WorkSheet workSheet.Replace("old", "new"); // Write new above old just in row no 6 of WorkSheet workSheet.Rows[5].Replace("old", "new"); // Write new above old just in column no 5 of WorkSheet workSheet.Columns[4].Replace("old", "new"); // Write new above old just from A5 to H5 of WorkSheet workSheet["A5:H5"].Replace("old", "new"); workBook.SaveAs("sample.xlsx"); Imports IronXL Private workBook As WorkBook = WorkBook.Load("sample.xlsx") Private workSheet As WorkSheet = workBook.GetWorkSheet("Sheet1") ' Write new above old in complete WorkSheet workSheet.Replace("old", "new") ' Write new above old just in row no 6 of WorkSheet workSheet.Rows(5).Replace("old", "new") ' Write new above old just in column no 5 of WorkSheet workSheet.Columns(4).Replace("old", "new") ' Write new above old just from A5 to H5 of WorkSheet workSheet("A5:H5").Replace("old", "new") workBook.SaveAs("sample.xlsx") $vbLabelText $csharpLabel For more information about how to write Excel .NET applications and more, check out our full tutorial on how to Open and Write Excel Files C#. Tutorial Quick Access Read API Reference Read the IronXL documentation including lists of all functions, features, namespaces, classes, and enums available to you in the library. Read API Reference Frequently Asked Questions How do I get started with writing Excel files in .NET? To get started with IronXL, download the library and include it in your project. Import the library by using 'using IronXL' in your C# code. How can I write a value to a specific cell in an Excel worksheet? To write a value to a specific cell using IronXL, access the cell using its address, such as worksheet['A1'], and assign a value using the .Value property. How do I assign a static value to a range of cells in Excel? To assign a static value to a range using IronXL, specify the range using cell addresses, like worksheet['B2:C5'], and set the .Value property to your desired static value. Can I write dynamic values to a range of cells in Excel? Yes, with IronXL, you can write dynamic values to a range using loops or custom logic. For example, you can iterate over cell addresses and assign dynamic values based on your requirements. How can I replace existing cell values in an Excel worksheet? Using IronXL, you can use the Replace() method on the worksheet, row, column, or specified range to replace 'old value' with 'new value'. What is the difference between using Value and StringValue? In IronXL, the .Value property may convert the assigned value to a type-specific format, while .StringValue assigns the value as a string, avoiding conversion. How can I open and access a specific worksheet in an Excel file? Use IronXL's WorkBook.Load('path/to/your/excel-file.xlsx') to load the file and workbook.GetWorkSheet('SheetName') to access a specific worksheet. Is it necessary to save the Excel file after writing new values? Yes, when using IronXL, you must save the Excel file after making changes by using the workbook.SaveAs('filename.xlsx') method to persist your changes. How do I write a new value to replace an old value in a specific row? With IronXL, access the row using worksheet.Rows[index] and then call the Replace() method with the old and new values. Can I replace values in a specific column? Yes, using IronXL, access the column using worksheet.Columns['A'] and use the Replace() method to substitute old values with new ones in that column. Chaknith Bin Chat with engineering team now Software Engineer Chaknith works on IronXL and IronBarcode. He has deep expertise in C# and .NET, helping improve the software and support customers. His insights from user interactions contribute to better products, documentation, and overall experience. Ready to Get Started? Free NuGet Download Total downloads: 1,487,525 View Licenses