作者:入贝_272 | 来源:互联网 | 2023-05-19 06:58
IhavebeentryingtospeedupamacrobyusingXLLs,however,itseemsisalotfasterwiththeUDF
I have been trying to speed up a macro by using XLLs, however, it seems is a lot faster with the UDF than with the XLL.
我一直试图通过使用XLL来加速宏,但是,使用UDF似乎比使用XLL快得多。
Some data with code profiling demonstrates it
一些带有代码分析的数据证明了这一点
XLL Time for the sub Proc:module 1 iteration 11.64831 seconds
子过程的XLL时间:模块1迭代11.64831秒
UDF Time for the sub Proc:module 1 iteration 4.25986 seconds
子过程的UDF时间:模块1迭代4.25986秒
It happens on two UDFs that I have converted, factor is abour 2x or 3x slower. For instance, the XLL function for this is:
它发生在我转换的两个UDF上,因子是2倍或3倍慢。例如,XLL函数是:
[ExcelFunction(Description="Joins cell values", Category="Example1")]
public static object RangeJoin(object[,] cells)
{
List list = new List();
foreach (object o in cells){
if ( !(o is ExcelEmpty) )
list.Add(o.ToString()); }
return string.Join(" ", list.ToArray());
}
The UDF Function is
UDF函数是
Function RangeJoin(Rng As Range) As String
Dim vArr As Variant
Dim v As Variant
vArr = Rng
RangeJoin = vbNullString
For Each v In vArr
RangeJoin = RangeJoin & " " & v
Next v
End Function
Both were tested for Range(A1:A701) with data and blanks between cells, both work as expected, just XLL is slower.
两者都测试了Range(A1:A701)的数据和单元格之间的空白,两者都按预期工作,只是XLL较慢。
1 个解决方案