Instantly share code, notes, and snippets.

Embed
What would you like to do?
Build Union of even lines with a fast approach based on divide and conquer.
private static Range UnionDivideAndConquer(int[] excelRows, int start, int end)
{
if (excelRows.Length == 0) return null;
if (start == end)
{
return ExcelAddIn.ActiveSheet.Range["A" + excelRows[start] + ":" + "C" + excelRows[start]];
}
int middle = (start + end) / 2;
Range left = UnionDivideAndConquer(excelRows, start, middle);
Range right = UnionDivideAndConquer(excelRows, middle + 1, end);
return ExcelAddIn.Application.Union(left, right);
}
public BuildUnionFast(int count)
{
var rowIndices = Enumerable.Range(1, 2*count+1).Where(k => k % 2 == 1).ToArray();
Range range = UnionDivideAndConquer(rowIndices, 0, rowIndices.Length-1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment