Excel Table

Hi,
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.

[218 byte] By [De@th] at [2008-2-23]
# 1

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:

Code Snippet

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());

}

}

Hope this helps! :-)

Thanks

Ji

JiZhou–MSFT at 2007-10-2 > top of Msdn Tech,Visual Studio Orcas,Visual Studio Tools for Office Orcas...

Visual Studio Orcas

Site Classified