Seb*_*ler 7 c# excel vba user-defined-functions excel-dna
当试图在VBA中调用以下Excel-DNA-Method时,我只获得一个大小为1的数组(在65536行之后,数组似乎被调整为实际数组大小--65537).当在工作表中调用方法作为数组函数时,整个过程都有效.
[ExcelFunction(Description = "Example", Name = "Example", HelpTopic = "")]
public static object[] example() {
object[] ret = new object[65537];
return ret;
}
Run Code Online (Sandbox Code Playgroud)
我正在使用Excel 2007,工作表是一个xlsm-Worksheet,当使用这样的二维数组时,一切正常.
[ExcelFunction(Description = "Example", Name = "Example", HelpTopic = "")]
public static object[,] example() {
object[,] ret = new object[65537,1];
return ret;
}
Run Code Online (Sandbox Code Playgroud)
但是使用二维数组的方式与发生的情况相反
[ExcelFunction(Description = "Example", Name = "Example", HelpTopic = "")]
public static object[,] example() {
object[,] ret = new object[1,65537];
return ret;
}
Run Code Online (Sandbox Code Playgroud)
有人知道如何解决这个问题吗?
在VBA中做同样的事情很好
Function test()
Dim ret As Variant
ReDim ret(65536)
test = ret
End Function
Sub testSub()
Dim output
output = Application.Run("test")
End Sub
Run Code Online (Sandbox Code Playgroud)
输出的维度为65537(索引从0开始),也是大于65537的数字.
鉴于您使用二维数组和翻转维度表示了不同的性能,听起来您遇到了行和/或列的限制。
此页:http://office.microsoft.com/en-us/excel-help/excel-specifications-and-limits-HP010073849.aspx给出了 Excel 2007 的限制。如您所见,工作表的限制为 16,384,您的值超出了许多倍。另一方面,行限制 1,048,576 可以轻松容纳值 65537。
我的猜测是,当您请求具有 65537 列的对象时,构造函数会默默地处理溢出并将其解析为 1。
| 归档时间: |
|
| 查看次数: |
1295 次 |
| 最近记录: |