|
void CMaintestDlg :: OnBtnRt ()
{
// TODO: Add your control notification handler code here
UpdateData (TRUE);
if (! objApp.CreateDispatch ("Excel.Application"))
{
AfxMessageBox ("Failed to create Excel service!");
return;
}
Ranch
Ranch
COleVariant vResult;
COleVariant
covTrue ((short) TRUE),
covFalse ((short) FALSE),
covOptional ((long) DISP_E_PARAMNOTFOUND, VT_ERROR);
objBooks.AttachDispatch (objApp.GetWorkbooks (), true);
objBook.AttachDispatch (objBooks.Open ("e:\\x.xls",
covOptional, covOptional, covOptional, covOptional, covOptional,
covOptional, covOptional, covOptional, covOptional, covOptional,
covOptional, covOptional, covOptional, covOptional));
// Get Worksheets
objSheets.AttachDispatch (objBook.GetWorksheets (), true);
// Get sheet1
objSheet.AttachDispatch (objSheets.GetItem (_variant_t ("Sheet1")), true);
// Get all Cells, at this time, objSheet is a collection of cells
bjRange.AttachDispatch (objSheet.GetCells (), true);
VARIANT vs = objRange.GetItem (_variant_t ((long) 1), _ variant_t ((long2));
m_rt1 = vs.dblVal; // m_rt1 is a variable of the dialog class, doule type
Ransom
UpdateData (FALSE);
objRange.ReleaseDispatch ();
objSheet.ReleaseDispatch ();
objSheets.ReleaseDispatch ();
objBook.ReleaseDispatch ();
objBooks.ReleaseDispatch ();
objApp.ReleaseDispatch ();
After running, m_tr1 does not display the value of the second line and the second cell in sheet1 in the file e:\\x.xls.
Originally it was 303.2, the result showed 3.75064, and then clicked the button again, the displayed number changed again.
Very strange, please enlighten me. |
|