C# Edit Excel File
Edit Excel files in C# using IronXL library which provides simple methods to modify cells, rows, columns, and worksheets programmatically without Excel Interop, reducing errors and complexity.
Developers need precision when modifying Excel files in C# because one error can corrupt entire documents. Simple, efficient code reduces error risk and simplifies programmatic editing or deletion of Excel files. IronXL provides a comprehensive solution for working with Excel files in C# that eliminates Microsoft Office dependencies. This guide covers the steps to edit Excel files in C# correctly and quickly using tested functions.
Quickstart: Edit a Specific Cell Value with IronXL
This example shows how to load an existing Excel file, update a single cell, and save changes using IronXL. Get started in under 5 lines, no Interop required. For complex operations, explore our comprehensive API Reference.
Get started making PDFs with NuGet now:
Install IronXL with NuGet Package Manager
Copy and run this code snippet.
IronXL.WorkBook.Load("file.xlsx").GetWorkSheet("Sheet1")["C3"].Value = "Hello IronXL"; // then save your workbook iroExcelWorkBook.SaveAs("file.xlsx");Deploy to test on your live environment
Minimal Workflow (8 steps)
- Download the C# Edit Excel Library
- Edit Specific Cell Values
- Edit full row values with a static value
- Edit full columns with a single value
- Edit Full Row with Dynamic Values
- Replace Spreadsheet Values
- Remove Row from Excel WorkSheet
- Remove WorkSheet from Excel File
Step 1
How Do I Set Up IronXL for C# Excel Editing?
This tutorial uses IronXL, a C# Excel library. Download and install it into your project (free for development) to use these functions. IronXL supports various platforms including Linux and macOS, making it versatile for cross-platform development.
You can either Download IronXL.zip or read more and install via the NuGet package page.
Once installed, let's get started. New to IronXL? Check our Get Started Overview for a comprehensive introduction.
Install-Package IronXL.Excel
Replace x.x.x with the appropriate version number as needed.
How to Tutorial
How Do I Edit Specific Cell Values in Excel?
First, learn how to edit specific cell values of an Excel SpreadSheet. This is one of the most common operations when editing Excel files in C#.
Import the Excel SpreadSheet to modify, then access its WorkSheet. Apply modifications as shown below. IronXL provides multiple ways to access cells, offering flexibility for different programming styles.
:path=/static-assets/excel/content-code-examples/how-to/csharp-edit-excel-file-specific-cell-value.csusing IronXL;
// Load the Excel workbook
WorkBook wb = WorkBook.Load("sample.xlsx");
// Access a specific worksheet
WorkSheet ws = wb.GetWorkSheet("Sheet1");
// Access specific cell by identifying its row and column, then modify its value
ws.Rows[3].Columns[1].Value = "New Value";
// Save changes to the workbook
wb.SaveAs("sample.xlsx");IRON VB CONVERTER ERROR developers@ironsoftware.comHere are before and after screenshots of Excel SpreadSheet sample.xlsx:
| Before | After |
|---|---|
![]() | ![]() |
Notice how simple it is to modify the Excel SpreadSheet value. This approach works well when updating specific data points without affecting the rest of your spreadsheet.
An alternative way to edit specific cell values by cell address:
// Alternative way to access specific cell and apply changes
ws["B4"].Value = "New Value";// Alternative way to access specific cell and apply changes
ws["B4"].Value = "New Value";' Alternative way to access specific cell and apply changes
ws("B4").Value = "New Value"How Do I Edit Full Row Values in Excel?
Edit full row values of an Excel SpreadSheet with a static value easily. This operation helps when updating entire records at once, such as resetting data or applying bulk updates. For complex row operations, explore adding rows and columns.
:path=/static-assets/excel/content-code-examples/how-to/csharp-edit-excel-file-row-value.csusing IronXL;
WorkBook wb = WorkBook.Load("sample.xlsx");
WorkSheet ws = wb.GetWorkSheet("Sheet1");
// Setting a static value for the entire row
ws.Rows[3].Value = "New Value";
wb.SaveAs("sample.xlsx");IRON VB CONVERTER ERROR developers@ironsoftware.comSee the screenshots of sample.xlsx below:
| Before | After |
|---|---|
![]() | ![]() |
Edit values of a specific range within a row using the range function:
// Editing a specific range of a row
ws["A3:E3"].Value = "New Value";// Editing a specific range of a row
ws["A3:E3"].Value = "New Value";' Editing a specific range of a row
ws("A3:E3").Value = "New Value"When working with ranges, you might also need selecting ranges for advanced operations like sorting or applying formulas.
How Do I Edit Full Column Values in Excel?
Edit full columns of Excel SpreadSheet values with a single value easily. This works well for scenarios like updating currency columns, applying new tax rates, or standardizing data formats across an entire column.
:path=/static-assets/excel/content-code-examples/how-to/csharp-edit-excel-file-full-column.csusing IronXL;
WorkBook wb = WorkBook.Load("sample.xlsx");
WorkSheet ws = wb.GetWorkSheet("Sheet1");
// Setting a static value for the entire column
ws.Columns[1].Value = "New Value";
wb.SaveAs("sample.xlsx");IRON VB CONVERTER ERROR developers@ironsoftware.comThis produces our sample.xlsx spreadsheet as shown:
| Before | After |
|---|---|
![]() | ![]() |
How Do I Edit a Full Row with Dynamic Values?
IronXL allows editing specific rows with dynamic values. Edit a full row by assigning dynamic values for each cell. This approach works well when importing data from databases or other sources requiring unique values per cell. See the example:
:path=/static-assets/excel/content-code-examples/how-to/csharp-edit-excel-file-full-row-dynamic.csusing IronXL;
using System.Linq;
WorkBook wb = WorkBook.Load("sample.xlsx");
WorkSheet ws = wb.GetWorkSheet("Sheet1");
for (int i = 0; i < ws.Columns.Count(); i++)
{
// Assign dynamic values to each cell in the row
ws.Rows[3].Columns[i].Value = "New Value " + i.ToString();
}
wb.SaveAs("sample.xlsx");IRON VB CONVERTER ERROR developers@ironsoftware.comThe table below shows screenshots of Excel SpreadSheet sample.xlsx from this output:
| Before | After |
|---|---|
![]() | ![]() |
How Do I Edit a Full Column with Dynamic Values?
Edit specific columns with dynamic values simply. This technique helps populate columns with sequential data like ID numbers, dates, or calculated values based on row position.
:path=/static-assets/excel/content-code-examples/how-to/csharp-edit-excel-file-full-column-dynamic.csusing IronXL;
using System.Linq;
WorkBook wb = WorkBook.Load("sample.xlsx");
WorkSheet ws = wb.GetWorkSheet("Sheet1");
for (int i = 0; i < ws.Rows.Count(); i++)
{
// Skip the first row if it's used as a header
if (i == 0)
continue;
// Assign dynamic values to each cell in the column
ws.Rows[i].Columns[1].Value = "New Value " + i.ToString();
}
wb.SaveAs("sample.xlsx");IRON VB CONVERTER ERROR developers@ironsoftware.comWith the table results of sample.xlsx below:
| Before | After |
|---|---|
![]() | ![]() |
How Do I Replace Spreadsheet Values in Excel?
Replace any value type with an updated value in an Excel SpreadSheet using the Replace function. Use this function to replace Excel SpreadSheet data in any required situation. This works well for data cleaning, updating terminology, or correcting systematic errors across spreadsheets.
How Do I Replace Values in an Entire Worksheet?
To replace a specific value throughout a complete Excel WorkSheet with an updated value, access the WorkSheet ws (same as above examples) and apply the Replace function:
// Replace a specific value in the entire worksheet
ws.Replace("old value", "new value");// Replace a specific value in the entire worksheet
ws.Replace("old value", "new value");' Replace a specific value in the entire worksheet
ws.Replace("old value", "new value")This function replaces old value with new value in a complete Excel WorkSheet. It's a powerful feature for bulk updates that would otherwise require manual find-and-replace operations in Excel.
Remember to save the file after any change, as shown in the examples above. For more information on saving and exporting Excel files, see our guide on converting spreadsheet file types.
How Do I Replace Values in a Specific Row?
To make changes to a specific row instead of the whole worksheet, use this code:
// Replace a specific value in a specific row
ws.Rows[2].Replace("old value", "new value");// Replace a specific value in a specific row
ws.Rows[2].Replace("old value", "new value");' Replace a specific value in a specific row
ws.Rows(2).Replace("old value", "new value")The above code replaces old value with new value only in row number 2. The rest of the WorkSheet remains unchanged.
How Do I Replace Values in a Row Range?
Replace values within a specific range as follows:
// Replace specific values in a row range
ws["From Cell Address : To Cell Address"].Replace("old value", "new value");// Replace specific values in a row range
ws["From Cell Address : To Cell Address"].Replace("old value", "new value");' Replace specific values in a row range
ws("From Cell Address : To Cell Address").Replace("old value", "new value")To replace an old value with a new value in the range from B4 to E4 of row number 4, write:
ws["B4:E4"].Replace("old value", "new value");ws["B4:E4"].Replace("old value", "new value");ws("B4:E4").Replace("old value", "new value")How Do I Replace Values in a Specific Column?
Replace values of a specific column while keeping the rest of the worksheet unchanged:
// Replace specific values in a column
ws.Columns[1].Replace("old value", "new value");// Replace specific values in a column
ws.Columns[1].Replace("old value", "new value");' Replace specific values in a column
ws.Columns(1).Replace("old value", "new value")The above code replaces old value with new value only for column number 1.
How Do I Replace Values in a Column Range?
Use the range function to replace within a range of a specific column:
// Replace specific values in a column range
ws["B5:B10"].Replace("old value", "new value");// Replace specific values in a column range
ws["B5:B10"].Replace("old value", "new value");' Replace specific values in a column range
ws("B5:B10").Replace("old value", "new value")The above code replaces old value with new value only within the range from B5 to B10 for column B.
How Do I Remove a Row from Excel Worksheet?
IronXL provides a simple function to remove a specific row of an Excel WorkSheet. This functionality helps when cleaning data or removing outdated records from spreadsheets. See the example:
:path=/static-assets/excel/content-code-examples/how-to/csharp-edit-excel-file-row-value.csusing IronXL;
WorkBook wb = WorkBook.Load("sample.xlsx");
WorkSheet ws = wb.GetWorkSheet("Sheet1");
// Setting a static value for the entire row
ws.Rows[3].Value = "New Value";
wb.SaveAs("sample.xlsx");IRON VB CONVERTER ERROR developers@ironsoftware.comThe above code removes row number 3 of sample.xlsx as shown in the following table:
| Before | After |
|---|---|
![]() | ![]() |
How Do I Remove a Worksheet from Excel File?
To remove a complete WorkSheet of an Excel file, use the following method. This helps when consolidating data or removing temporary worksheets used for calculations. For more information on managing worksheets, see our guide on managing worksheets.
// Remove a worksheet by its index
wb.RemoveWorkSheet(1); // by sheet indexing// Remove a worksheet by its index
wb.RemoveWorkSheet(1); // by sheet indexing' Remove a worksheet by its index
wb.RemoveWorkSheet(1) ' by sheet indexingwb is the WorkBook, same as in the above examples. To remove a worksheet by name:
// Remove a worksheet by its name
wb.RemoveWorkSheet("Sheet1"); //by sheet name// Remove a worksheet by its name
wb.RemoveWorkSheet("Sheet1"); //by sheet name' Remove a worksheet by its name
wb.RemoveWorkSheet("Sheet1") 'by sheet nameIronXL includes many more functions for easily performing any type of editing and deletion in Excel SpreadSheets. Explore additional features like creating Excel charts, applying conditional formatting, or working with formulas. Contact our dev team with any questions about using IronXL in your project.
Library Quick Access
IronXL Library Documentation
Explore the full capabilities of IronXL C# Library with various functions for editing, deleting, styling, and perfecting your Excel workbooks.
IronXL Library DocumentationFrequently Asked Questions
How do I edit Excel files in C# without Microsoft Office installed?
IronXL allows you to edit Excel files in C# without requiring Microsoft Office or Excel Interop. It provides a standalone library that can modify cells, rows, columns, and worksheets programmatically, eliminating Office dependencies and working across platforms including Linux and macOS.
What is the simplest way to update a cell value in an Excel file using C#?
With IronXL, you can update a cell value in just a few lines of code: IronXL.WorkBook.Load("file.xlsx").GetWorkSheet("Sheet1")["C3"].Value = "Hello IronXL"; followed by saving the workbook. This approach requires no Excel Interop and provides direct cell access.
Can I edit entire rows and columns in Excel programmatically?
Yes, IronXL supports editing full rows and columns with either static or dynamic values. You can modify entire rows with a single value, populate columns programmatically, or update rows with dynamic data from various sources like databases or calculations.
How do I remove rows or worksheets from an Excel file in C#?
IronXL provides simple methods to remove rows from worksheets and delete entire worksheets from Excel files. These operations are performed programmatically without requiring Excel to be installed, making it ideal for server-side applications.
Is it possible to find and replace values throughout an Excel spreadsheet?
Yes, IronXL includes functionality to search and replace values across spreadsheets. You can programmatically find specific values and replace them with new data, similar to Excel's native find and replace feature but automated through C# code.
What platforms does the C# Excel editing library support?
IronXL supports multiple platforms including Windows, Linux, and macOS, making it versatile for cross-platform development. This allows you to edit Excel files in C# applications regardless of the deployment environment.
How do I get started with editing Excel files in C#?
To get started, download and install IronXL via NuGet package manager. The library is free for development use. Once installed, you can immediately begin loading Excel files, modifying cells, and saving changes with simple, intuitive code.
What are the advantages of programmatic Excel editing over manual methods?
IronXL enables programmatic Excel editing which reduces human error, automates repetitive tasks, and allows for bulk operations that would be time-consuming manually. It also eliminates the need for Excel Interop, reducing complexity and improving performance.


















