Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default xlCoerce on multi-part xRef

hello

how do i use the C API to get at the contents of a multi-part range?

more specifically how to i run xlCoerce on a reference xRef where
xRef-val.mref.lpmref-count 1 ?

consider the function below which takes a range as the sole input
parameter, and for each cell in that range writes the cell's contents
to a logfile:

__declspec(dllexport) int WINAPI getRange(LPXLOPER xRef) {
//omitted - set up logfile log1 and try/catch
XLOPER xGet, xDestType;
xDestType.xltype = xltypeNum;
xDestType.val.num = xltypeMulti;
if (xlretSuccess != Excel(xlCoerce, &xGet, 2, xRef, &xDestType)) {
throw exception("unable to coerce input range");
}
for (int i = 0; i < xGet.val.array.rows * xGet.val.array.columns;
i++) {
// assume all the cells contain xltypeNums
log1 << i << " - " << xGet.val.array.lparray[i].val.num << endl;
}
}

the above function works as i expect when i call it from VBA and pass
a single-part range as the parameter:

ret = Application.Run("getRange", Range("A1:C2"))

but of course the function prints out gibberish if i pass it a
multi-part range:

ret = Application.Run("getRange", Range("A1:C2,A4:B5"))

how do i handle the second case? the best i've come up with so far is
to create a local reference to a one-part range, and copy the contents
of the multi-part range into the one-part range one chunk at a time:

__declspec(dllexport) int WINAPI getRange(LPXLOPER xRef) {
XLOPER xRefCopy, xGet, xDestType;
xRefCopy.xltype = xltypeRef;
xRefCopy.val.mref.idSheet = xRef-val.mref.idSheet;
xRefCopy.val.mref.lpmref = new XLMREF [ 1 ];
xRefCopy.val.mref.lpmref-count = 1;
xDestType.xltype = xltypeNum;
xDestType.val.num = xltypeMulti;
for (int i = 0; i < xRef-val.mref.lpmref-count; i++) {
log1 << i << " ***" << endl;
xRefCopy.val.mref.lpmref-reftbl[0].rwFirst
= xRef-val.mref.lpmref-reftbl[i].rwFirst;
xRefCopy.val.mref.lpmref-reftbl[0].rwLast
= xRef-val.mref.lpmref-reftbl[i].rwLast;
xRefCopy.val.mref.lpmref-reftbl[0].colFirst
= xRef-val.mref.lpmref-reftbl[i].colFirst;
xRefCopy.val.mref.lpmref-reftbl[0].colLast
= xRef-val.mref.lpmref-reftbl[i].colLast;
if (xlretSuccess != Excel(xlCoerce, &xGet, 2, &xRefCopy,
&xDestType)) {
throw exception("unable to coerce input range");
}
for (int j = 0; j < xGet.val.array.rows * xGet.val.array.columns;
j++) {
log1 << j << " - " << xGet.val.array.lparray[j].val.num << endl;
}
}
}

that does what i want, but surely there's a better way.

TIA
eric
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding Multi-part Formula PhilosophersSage Excel Discussion (Misc queries) 3 October 6th 09 06:37 PM
Multi Part Lookup MikeD1224 Excel Discussion (Misc queries) 3 April 18th 08 06:56 PM
Find last name in multi-part name? Eric Excel Worksheet Functions 4 November 1st 07 04:51 PM
Complex Multi-condition, multi-workbook count Heliocracy Excel Discussion (Misc queries) 0 October 4th 07 08:18 PM
how can I paste multi-line/multi-paragraph data into ONE cell? Theano Excel Discussion (Misc queries) 3 June 7th 05 01:10 PM


All times are GMT +1. The time now is 05:08 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"