Excel Table
this might be a really stupid question, but I need to retrieve data from all Tables (Insert->Table) within active worksheet. I have no Idea how to do it. Would someone be so kind and help me?
Thanks.
Thanks.
Hi,
If you record a Macro, you will see the table is Excel.ListObject in fact. You can try the following codes to retrieve data from all Tables. It works in my side:
object missing = Type.Missing; Excel.Application myApp = new Microsoft.Office.Interop.Excel.Application(); myApp.Visible = true; myApp.Workbooks.Open(@"C:\book1.xlsx",missing,missing,missing,missing,missing, missing,missing,missing,missing,missing,missing,missing,missing,missing); Excel.Worksheet myWS = myApp.ActiveSheet as Excel.Worksheet; foreach (Excel.ListObject myLO in myWS.ListObjects) { foreach (Excel.ListRow lr in myLO.ListRows) { MessageBox.Show(lr.Range.Text.ToString()); } } Code Snippet
Hope this helps! :-)
Thanks
Ji