I’m trying to get a range from Excel, which has multiple areas specified, essentially I’ve got…
int StartColumn
int EndColumn
int[] ColumnsToSkip
When you combine these it’s possible to produce a range with non-contiguous areas. Unfortunately I can’t quite figure out the call to get this… MSDN isn’t very useful…
WorkSheet sheet;
sheet.get_Range( what goes in here??? );
Anyone provide any help? Cheers.
A very simple solution is to specify different areas in comma-separated form:
For programmatic range combinations, there are also the
UnionandIntersectionmethods of the ExcelApplication object. Those are a little bit clumsy to use in C# because of many optional parameters. See herehttp://codeidol.com/csharp/c-sharp-in-office/Working-with-Excel-Objects/Working-with-the-Range-Object/
for examples.
EDIT: some additional hints:
In your case, you first should transform the “ColumnsToSkip” in “ColumnsToKeep”, since that is what you will need for any kind of cell union. Here is a Linq solution:
Then, you can create something along the lines of this example:
where “Union” is defined, for example, like this: