Solved

Excel   _Application.Run with array as parameter

Posted on 2000-05-15
1
287 Views
Last Modified: 2013-11-20
In vb the call looks like this

ExcelApp---Excel.Application

dim MyArray(2)as double
MyArray(1)=1
MyArray(2)=2
ExcelApp.Run("SomeFunc",MyArray)
Works well

How can I do that in MFC
My code is like:
_______________________________________
COleVariant FuncName;FuncName.bstrVal= SysAllocString(L"SomeFunc");
COleVariant MyArray;
double tmp[2]={1,2};
PutValues(&MyArray,tmp,2);
m_ExcelApp.Run(FuncName,MyArray);


The put values function is:
_______________________________________
void PutValues(COleVariant  *ThisArray, double *Arr, long nCount)
{
      int i = 0;      
      long *palDims = 0;
      double      rValue = 0.0;
      SAFEARRAY *psaData = 0;
      SAFEARRAYBOUND *pabound = 0;
      HRESULT      hRes = 0;      

      VariantInit( ThisArray );
        pabound = (SAFEARRAYBOUND *) malloc( 2 * sizeof(SAFEARRAYBOUND) );
      palDims = (long *) malloc( 2 * sizeof(long) );
      if( pabound && palDims )
            {
            pabound[0].cElements = nCount;
            pabound[0].lLbound = 0L;
            pabound[1].cElements = 1;
            pabound[1].lLbound = 0L;
            psaData = SafeArrayCreate( VT_R8, 2, pabound );
            for( i = 0; ( i < nCount) && ( hRes == S_OK) ; i++ )
            {
                palDims[0] = i;
              palDims[1] = 0;
              hRes = SafeArrayPutElement( psaData, palDims,&Arr[i]);
            }
             ThisArray->parray = psaData;
                ThisArray ->vt = VT_R8;
            ThisArray->vt|= VT_ARRAY;
            }
            free( pabound );
            free( palDims );
}


0
Comment
Question by:mdanny
1 Comment
 
LVL 23

Accepted Solution

by:
naveenkohli earned 50 total points
ID: 2815250
Look at this Microsoft knowledge base article.

Article ID: Q186122
 

HOWTO: Use MFC to Automate Excel & Obtain an Array from a Range

http://support.microsoft.com/support/kb/articles/q186/1/22.asp

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
repeatSeparator  java  challenge 13 56
fizzArray  challenge 1 57
haveThree challenge 22 112
Is there a simple front-end menu system. 9 69
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now