0

我正在开发一个 Excel 插件!我想在不使用Xlapp.Union(递归方式)的情况下创建一个单元格联合( range ),只需在一个字符串中给出一对单元格(x,y) !

我尝试使用 XLapp.Union 但它真的很慢,然后我正在寻找一种新方法来做同样的事情,只需将 cellsAdress 作为字符串。

我正在寻找一个接受参数字符串的函数:像这样(“A1,B3,C5...”)并重新计算一个范围!

我试过: Range RE = ExcelWorkbook.ActiveSheet.get_Range(RgEvenString, Type.Missing); 其中 RgEvenString 是一个字符串,例如:“A1,B3,C5...” ,它会引发异常!

任何人都可以帮助PLZ!

4

2 回答 2

1

http://social.msdn.microsoft.com/Forums/en-US/abf5a953-caa2-44c1-9723-fb7b1d99f2fc/how-to-reference-noncontiguous-selected-rows-in-excel?forum=isvvba

Check out this link for a way to reference noncontiguous cells in Excel. The link is in VBA but you should be able to apply it to C#. Consider mimicking the "selection" from that post by creating your own "selection" from parsing the string containing the cell addresses.

By the way, how slow is Union? Can you post an example of the way you're using the Union function in context with the other code? Maybe there's something else that can be optimized.

于 2013-10-22T14:58:14.367 回答
-1
public static Range OldUnionRange(List<System.Drawing.Point> list,Range range, Boolean Even){
Range RgEven = null;
Boolean RgEvenBool = false;
Range RgOdd = null;
Boolean RgOddBool = false;
for (int j = 0; j < list.Count; j++){
System.Drawing.Point p = list[j];
int x = p.X;
int y = p.Y;
if (x % 2 == 0 && Even)
{Range rng = range.Cells[x + 1, y + 1];
if (!RgEvenBool){
RgEven = range.Cells[x + 1, y + 1];
RgEvenBool = true;
}
RgEven = Shuttle_add_in_Loader.XlApp.Union(RgEven, rng);
}
else if (x % 2 != 0 && !Even)
{Range rng = range.Cells[x + 1, y + 1];
if (!RgOddBool)
{
RgOdd = range.Cells[x + 1, y + 1];
RgOddBool = true;
}
RgOdd = Shuttle_add_in_Loader.XlApp.Union(RgOdd, rng);
}
}
if (Even)
{
return RgEven;
}
else
{return RgOdd;}
}
于 2013-10-23T11:27:36.593 回答