XLL命令(不是UDF):xlSet无法设置多个值

我对XLL编程很新,但是我相信我已经在这个小问题上做了功课。 我想使用xlSet设置多个单元格值,但xlSet只是复制我的数组的第一个值,就好像我已经通过它一个单一的引用。 如果我连续调用每个单元格的xlSet,它的工作原理。 但它很丑,毫无疑问,速度很慢。

我知道xlSet不能从UDF调用。 这不是一个UDF。 在其他地方,我看到有人在xlMulti中有一个结构alignment问题,但是我将同一个xlMulti发送回Excel,所以这不是问题。 (无论如何,我试过/ Zp8编译器开关。)

我开始使用SDK Framework的东西,例如TempActiveRef(1,1,0,2),然后用更直接的XLCALL.H来replace那些调用,主要是为了增加我在这里得到响应的机会。

Office 2010,VSTO 2010,Win7 64bit SP1。

这是什么工作,什么不工作:

__declspec(dllexport) int WINAPI testCmd(void) { XLOPER12 ref, xValsInMulti, xResSet; XLMREF12 mref; int i, res; // Build an xltypeRef XLOPER12 that points to three cells, A2:C2 res = Excel12(xlSheetId, &ref, 0); if (res != xlretSuccess) return 0; ref.xltype = xltypeRef; ref.val.mref.lpmref = &mref; mref.count = 1; mref.reftbl[0].rwFirst = mref.reftbl[0].rwLast = 1; mref.reftbl[0].colFirst = 0; mref.reftbl[0].colLast = 2; // Fetch the cell values into an xltypeMulti. // This works. Returns 0. And xValsInMulti.type becomes xlTypeMulti res = Excel12(xlCoerce, &xValsInMulti, 1, &ref ); // Change cell reference to the next row (A3:C3) mref.reftbl[0].rwFirst = mref.reftbl[0].rwLast = 2; // Attempt to set the values. Doesn't work. All cells become value of A2. Excel12(xlSet, &xResSet, 2, &ref, xValsInMulti); Excel12(xlcAlert, 0, 1, &xResSet); // Displays "TRUE" // Try again (in the next row) setting each cell individually. This works. mref.reftbl[0].rwFirst = mref.reftbl[0].rwLast = 3; for (i=0; i<3; i++) { mref.reftbl[0].colFirst = mref.reftbl[0].colLast = i; Excel12( xlSet, &xResSet, 2, &ref, xValsInMulti.val.array.lparray+i ); Excel12(xlcAlert, 0, 1, &xResSet); // Displays "TRUE" } Excel12(xlFree, 0, 1, &xValsInMulti); return 1; }