Please help!

  • Thread starter Thread starter Eric.Z
  • Start date Start date
Joined
12/13/11
Messages
83
Points
18
Does anyone know how to pass an Excel range to a function written in a C++ dll?
 
crazymath, you can send it as one dimensional array of simple type (double or int). if you want to send matrix (2 dim array) just convert 2 dim into 1 dim and convert back in C++ code. If I remember right you may find this approach in Dalton book I gave you link to last time.
 
Code:
Vector<DOUBLE> ExcelUtils::ExcelRangeToVector(Excel::RangePtr pRange)
{
    // Get the number of rows and columns in the range
    int columns=pRange->Columns->Count;
    int rows=pRange->Rows->Count;
 
    // Create the vector with the correct size
    Vector<DOUBLE> v(columns*rows);
 
    // Iterate the rows and columns
    int index=v.MinIndex();
    for (int r=1; r<=rows; r++)
    {
        for (int c=1; c<=columns; c++)
        {
            // Add each element in the range to our vector
            v[index++]=(((Excel::RangePtr)pRange->Item[r][c])->Value).dblVal;
        }
    }
 
    // Return the vector
    return v;
}
You can use the Excel Object Model
 
Back
Top Bottom