Skip to content

Instantly share code, notes, and snippets.

@bpatra
Last active December 5, 2020 18:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bpatra/7170224 to your computer and use it in GitHub Desktop.
Save bpatra/7170224 to your computer and use it in GitHub Desktop.
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