How to read an Excel file using C#
The following program illustrates how to open an existing Excel spreadsheet in C# using .NET Framework COM interop capability. Also you can see how to find Named Ranges in Excel and get the range of occupied cells (Used area) in excel sheet.
Excel Reader using Excel Interop
The following C# source code using Microsoft Excel 12.0 Object Library for reading an Excel file. In the previous section we saw how to import Microsoft Excel 12.0 Object Library in the CSharp project .
How to specify a range in Excel sheet?
If you want to select a specific cell in Excel sheet, you can code like this.
Reading Named Ranges in Excel
If you want to select multiple cell value from Excel sheet, you can code like this.
How to get the range of occupied cells in excel sheet
For reading entire content of an Excel file in C#, we have to know how many cells used in the Excel file. In order to find the used range we use "UsedRange" property of xlWorkSheet . A used range includes any cell that has ever been used. It will return the last cell of used area.
When you execute this C# source code the program read all used cells from Excel file.
- How to create Excel file in C#
- How to open an Excel file in C#
- How to programmatically Add New Worksheets
- How to delete worksheet from an excel file
- How to format an Excel file using C#
- How to insert a picture in excel from C# App
- How to insert a background picture in excel
- How to create Excel Chart from C#
- How to export excel chart from C#
- How to excel chart in C# picturebox
- C# data validation input box in excel file
- Read and Import Excel File into DataSet or DataTable
- How to insert data to Excel file using OLEDB
- How to update data in Excel file using OLEDB
- How to export databse to excel file
- How to export DataGridView to excel file