I'm writing a program (in C#, using Microsoft.Office.Interop.Excel) that reads in an Excel spreadsheet and applies filters, etc. to the data within. However, I'm struggling with a few issues, namely how to "get" a table object representing the table of data I am working with. I'd like to be able to access columns by their headers as well, so I assumed that I would require the DataTable namespace. I can't seem to figure out what to do, however.
Here is the rough framework of my code:
private void Process(Workbook workBook)
{
try
{
Worksheet sheet = workBook.Sheets["x"];
Range range = sheet.UsedRange;
// what goes here in order to access columns by name?
}
catch (Exception ex)
{
}
}
I'm really not sure of how to go about this, so any help, as well as any suggestions for useful articles about how to use Microsoft.Office.Excel.Interop, is really welcome. I really haven't been able to find many resources that fit my needs. Thank you very much!
I use EPPLUS all the time, you can get it via NuGet. Use EPPLUS instead of Microsoft.Office.Excel.Interop
Best thing since sliced bread.
Here is a stackoverflow link to show how to export to Excel
Here is how to import excel into a datatable
Following code snippet demonstrates the technique of exporting data from .NET
DataTable
to Excel Workbook using C# andMicrosoft.Office.Interop.Excel
:Hope this will help. Regards,