open an excel file in c# in csharp

To open an Excel file in C#, you can use the Excel Interop library. Here is an example code snippet:

main.cs
using Microsoft.Office.Interop.Excel;

// ...

Application excel = new Application();
Workbook workbook = excel.Workbooks.Open(@"C:\path\to\file.xlsx");
Worksheet worksheet = workbook.ActiveSheet;

// Now you can access the cells and data in the worksheet:
Range range = worksheet.Range["A1"];
string cellValue = (string) range.Value;
335 chars
12 lines

This code creates a new instance of the Excel Application class, opens a specific workbook file, and then gets a reference to the active worksheet. From there, you can access individual cells and data within the worksheet by using the Range property.

gistlibby LogSnag