Last active
December 5, 2020 18:22
-
-
Save bpatra/7170224 to your computer and use it in GitHub Desktop.
The basic Union method in ExcelInterop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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