简体   繁体   中英

C# Excel Interop: how can I “get” a table that is already in a worksheet?

My worksheet has a number of tables. I need to manipulate one in particular. Of course I could simply look at its cell numbers and manipulate it cell by cell, but is there any "get" function to "get" the table programatically?

And if so, how would I then manipulate the cells? Is there a command to "get" the entire header, or an entire column by its header (rather than its column number)/

If anyone knows of a guide that explains this, that would be sufficient. I tried googling it but all the results are about database tables, ie populating a spreadsheet from a DB.

Swift, I'm working on something similar and I ran across this article which helped me.

In short, references to tables can be found in a worksheets list objects. Iterating through the list object and requesting the range or datarange should get you what you need.

I also found this article which has very similar info.

All these examples are in VBA or VB but I found it not to difficult to port over.

-M

When you say a table, I assume you mean a range. The following code will get a range from within an VS2010 Excel Add-In -

Excel.Worksheet activeWorksheet = ((Excel.Worksheet)Application.ActiveSheet);
Excel.Range myRange = activeWorksheet.get_Range("A1", "D20");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM