views:

528

answers:

2

Without:

  • MFC
  • ATL

using COM, with pure C++, steps taken thus far:

//steps above omitted

_ApplicationPtr application(__uuidof(Excel::Application));

//omitted

const BSTR wcharFileName = SysAllocString(L"...");

application->Workbooks->Open(wcharFileName);

application->put_Visible(10, true);

Question:

  • How to then copy a cell, for instance A4, B4 and C4, into an array?
+2  A: 

Try this http://support.microsoft.com/kb/216388/en-us

João Augusto
MAN! Thanks a lot! I wish I could vote twice - hope this question helps others :)
Aaron
Glad it helped. :)
João Augusto
A: 

I earlier posted that

"For Excel - COM using C++

http://shaktisaran.tech.officelive.com/ExcelCOM.aspx

It also has Windows Programming tutorials."

I've deleted that post because it wouldn't help easily.

I'm providing more info related to example on web-site,

In ExcelProcessor.cpp

ReadRange function reads a range of Excel cells but you need to read a cell of data.

ShowAddedCells function writes to an Excel cell which you can use like below.

In ShowAddedCells function,

//Comment the following /* DISPID dispidPUT = DISPID_PROPERTYPUT;

DISPPARAMS dparams = {vDblVal, &dispidPUT, 1, 1};

EXCEPINFO excepinfo;

hr = pXlCell->Invoke(dispID, IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_PROPERTYPUT, &dparams, NULL, &excepinfo, NULL); */

//Add the following DISPPARAMS dparams = {NULL, NULL, 0, 0};

EXCEPINFO excepinfo;

VARIANT vResult; VariantInit(&vResult);

hr = pXlCell->Invoke(dispID, IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_PROPERTYGET, &dparams, &vResult, &excepinfo, NULL);

//You get the cell value in vResult

So you create a ReadCell function like ShowAddedCells function.

Shakti Saran