Problem passing a large safearray to Excel

B

Bill Below

I am automating Excel 2000 from a MFC program prepared in VC++2003 and
running in Win2K. Is C++ allowed here? I fill 2 COleSafeArray objects with
data and pass them to Excel as follows:

oRange.put_Value(COleVariant(saValues));
oRange.put_NumberFormat(COleVariant(saNumFormat));

For small ranges, this works fine; but when the range gets to a certain
size, say 750 rows and 8 columns, put_NumerFormat() returns an exception with
code 0x80020005. This happens for put_NumberFormat only, not for put_Value.
This does not seem to depend on the contents of saNumFormat. It can be empty
or filled compeletely with a simple format, "0", and the same thing happens.
No cells in Excel receive a number format.

If I run the same program from an XP machine with Excel 2003 installed the
problem goes away. So someday this will not be a problem. But for now I
need to support the earlier versions. Anyone know about this behavior and a
way to avoid it?

Thanks,
Bill Below
 
P

Peter T

Hi Bill,

If you find 682 x 8 works but one more row fails it's probably due to the
5462 max element limit that hits many things with arrays in xl97 & xl2000.

Perhaps something like -
if xlVer < 10 then
do multiple arrays under 5462 elements
else: normal way

Regards,
Peter T
 
B

Bill Below

Thanks, Peter. That was it. The KB to read is 177991 if anyone want to
follow up.

Bill
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top