You do not need to pass strTableName to your method since you never use it.
If you use @ "for strings, you donβt need to avoid things: @" c: \ users .... ";
You get an exception because you are trying to pin strings that don't actually exist. This is what your method should look like if I correctly understand your goal here.
public static void Ignore_Names(DataSet sheet) { var table = sheet.Tables[0]; var columns = table.Columns; var nameColumn = columns["Name"]; var names = new List<string>(); foreach (DataRow row in nameColumn.Table.Rows) names.Add(row[0].ToString().ToLower());
In addition, in the MainWindow constructor, you should simply do this after installing excel:
Ignore_Names(excel); dataGrid1.ItemsSource = excel.Tables[0].DefaultView;
Note that I am setting the ItemsSource, not the DataContext, and I am passing the DefaultView. You can completely remove the ItemsSource binding from XAML.
You really should use VSTO instead of DataSets, but this is one more thing to find out :)
source share