I've been trying to write "early binding" code to control Excel with Automation. I've made considerable progress but can't figure out how to write a SAFEARRAY of numbers to Excel. Here is some simplified code:

Code:
CComPtr<_Application> m_pXLApp;
CComPtr<Workbooks> m_pWorkBooks;
CComPtr<_Workbook> pBook;
CComPtr<Sheets> m_pSheets;
CComPtr<_Worksheet> pSheet;
CComPtr<Range> pRange;
CComPtr<IDispatch> pDisp;
COleSafeArray saRet;  //holds the data
BSTR filename;

m_pXLApp.CoCreateInstance(L"Excel.Application", nullptr, CLSCTX_LOCAL_SERVER);
m_pXLApp->get_Workbooks(&m_pWorkBooks);
m_pWorkBooks->Open(filename, ...);
m_pWorkBooks->Add(vOptional, LOCALE_SYSTEM_DEFAULT, &pBook)
pBook->get_Sheets(&m_pSheets);
m_pSheets->get_Item(CComVariant(nXLWorksheetNo), &pDisp);
pDisp->QueryInterface(&pSheet);
pSheet->get_Range(vVar1, vVar2, &pRange);
pRange->SetValue(COleVariant(saRet));
This simplified code looks good except there is no SetValue function for pRange. In fact, pRange is very limited in the number of functions available. How do you send an array of data to Excel using early binding?