Skip to content

Instantly share code, notes, and snippets.

@bpatra bpatra/BasicUnion
Last active Dec 26, 2015

What would you like to do?
The basic Union method in ExcelInterop
//builds the union range form the indices
private static Range Union(IEnumerable<int> rows)
Range range = null;
foreach (int row in rows)
var currentLine = ExcelAddIn.ActiveSheet.Range["A" + row + ":" + "C" + row];
range = range == null ? currentLine : ExcelAddIn.Application.Union(range, currentLine);
return range;
//and use it with all indices from 1 to count
public BuildUnionAll(int count)
var rowIndices = Enumerable.Range(1, count);
Range range = Union(rowIndices);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.