Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Excel   _Application.Run with array as parameter

Posted on 2000-05-15
1
Medium Priority
?
302 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 23

Accepted Solution

by:
naveenkohli earned 150 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

604 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