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

There are several tables in my worksheet. I need to manage it in particular. Of course, I could just look at its cell numbers and manipulate it with a cell in the cell, but is there any “get” function to “get” the table programmatically?

And if so, how will I manipulate the cells? Is there a command to “get” the whole heading or the whole column with its heading (and not its column number) /

If anyone knows the guide explaining this, that will be enough. I tried to do a Google search, but all the results are related to database tables, i.e. populating a spreadsheet from the database.

+4
source share
2 answers

Quickly, I am working on something similar, and I came across this article that helped me.

In short, table links can be found in the worksheet list objects. Iterating through a list object and querying a range or datarange should provide you with what you need.

I also found this article which has very similar information.

All of these examples are in VBA or VB, but I found that it is not difficult to port.

-M

+5
source

When you say a table, I assume that you mean a range. The following code will get the range from the built-in VS2010 Excel add-in -

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

Source: https://habr.com/ru/post/1402363/


All Articles