Excel 2002 ?? Excel 2000 ?? Excel 2002 ???????? ?? Excel 2000 ??? ?? ?????? ?? ??? ???? ?? ??????? ???? ?? ??? MFC ?? ????? ???? ????

???? ?????? ???? ??????
???? ID: 186122 - ?? ???????? ?? ?????? ??? ?? ?? ???? ???? ???? ??.
??? ?? ??????? ???? | ??? ?? ??????? ????

?? ????? ??

??????

?? ???? ????????? ???? ?? ?? Microsoft Excel ?? ???????? ???? ?? ??? ???? ???? multi-cell ?????? ?? ??? ???? ?? ???? ?????

???? ???????

?????? ?? ??-??-?? ?????? ???? ???? multi-cell ?????? ?? ??? ????, ???? ?? ??? ?? ?????? ???????? ?? GetValue ????? ?????? ?? ??? ?? ?? VARIANT ?? ????? ?? ??? ????? ???? ?????? ?? ?? ??? SAFEARRAY VARIANT GetValue ?? ?? ?? ?????? ?????? SAFEARRAY ??, ?? ?? ??? ?? ?? ???? GetElement ?? ????? ?? ????? ???? ???? ????? ????? ?? ?? ????????? ?? illustrate ?? demonstrate ?? ?? ?? ???????? ?? ???????? ???? ?????? ?? ???? ????

Microsoft Excel 2000 ?? 2002 ??????? ?? ??? ???

?? ??? ??? ????? ??? Excel 97 ???????? ????????? (Excel 8.olb) ?? ??????? wrappers ???? ?? ????? ???? ??? Slight ?????? ?? ??? ?? ??? Excel 2000 (Excel9.olb) ?? Excel 2002 (Excel.olb) ?? ??? ???? wrappers ?? ????? ???? ?? ?? ??????? ??????? ?? ??? ???? ???? ?? ???? ???Microsoft Excel 2000 ?? 2002 ?????? ????????? ?? ??? ?? ???? ??? ???? ?? ????? ??? ?? ????? ???? ?? ???? ??? ???????? ??????? ?? ??? Microsoft ???????? ??? ???? ????? ?? ??? ????? ???? ?????? ?? ????? ????:
224925?????: Office ?? ??? ?????? ??????????? ?? ???? ????? ?? ?? ????

????????? ????? ?? ??? ???

  1. Microsoft Excel ??? ???? ?? ????????????? ?????? ?????? ?? ????????? ???????? ?? ???????? ???? ?? ?? mixture ???? A1:C8. "C:\test.xls" ?? ??? ??? ????????????? ?? ??????, ?? Microsoft Excel ?? ???? ???????
  2. ??? 1 ?? 12 ??? ????? ???? ?? Microsoft ???????? ??? ????? ?? ????? IDispatch interfaces ?? ????? ?????? Excel8.olb ?????? ????????? ??? ????????? ????? ????????? ????? ?? ??? ?? ???? ????:
    178749??????? ????????? MFC ?? ?? ?????? ????????? ?? ????? ?? ????? ???? ????
  3. AutoProjectDlg.cpp ????? ?? ????? ?? ????? ?????? ??????:
          #include "excel8.h"
    					
  4. CAutoProjectDlg::OnRun() AutoProjectDlg.cpp ????? ??? ????? ??? ??????:

    ????? ???

          // OLE Variant for Optional.
          COleVariant VOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
    
          _Application objApp;
          _Workbook objBook;
          Workbooks objBooks;
          Worksheets objSheets;
          _Worksheet objSheet;
          Range objRange;
          VARIANT ret;
    
          // Instantiate Excel and open an existing workbook.
          objApp.CreateDispatch("Excel.Application");
          objBooks = objApp.GetWorkbooks();
          objBook = objBooks.Open("C:\\Test.xls",
                    VOptional, VOptional, VOptional, VOptional,
                    VOptional, VOptional, VOptional, VOptional,
                    VOptional, VOptional, VOptional, VOptional);
          objSheets = objBook.GetWorksheets();
          objSheet = objSheets.GetItem(COleVariant((short)1));
    
          //Get the range object for which you wish to retrieve the
          //data and then retrieve the data (as a variant array, ret).
          objRange = objSheet.GetRange(COleVariant("A1"), COleVariant("C8"));
          ret = objRange.GetValue();
    
          //Create the SAFEARRAY from the VARIANT ret.
          COleSafeArray sa(ret);
    
          //Determine the array's dimensions.
          long lNumRows;
          long lNumCols;
          sa.GetUBound(1, &lNumRows);
          sa.GetUBound(2, &lNumCols);
    
          //Display the elements in the SAFEARRAY.
          long index[2];
          VARIANT val;
          int r, c;
          TRACE("Contents of SafeArray\n");
          TRACE("=====================\n\t");
          for(c=1;c<=lNumCols;c++)
          {
             TRACE("\t\tCol %d", c);
          }
          TRACE("\n");
          for(r=1;r<=lNumRows;r++)
          {
             TRACE("Row %d", r);
             for(c=1;c<=lNumCols;c++)
             {
                index[0]=r;
                index[1]=c;
                sa.GetElement(index, &val);
                switch(val.vt)
                {
                case VT_R8:
                   {
                      TRACE("\t\t%1.2f", val.dblVal);
                      break;
                   }
                case VT_BSTR:
                   {
                      TRACE("\t\t%s",(CString)val.bstrVal);
                      break;
                   }
    
                case VT_EMPTY:
                   {
                      TRACE("\t\t<empty>");
                      break;
                   }
                }
             }
             TRACE("\n");
          }
    
          //Close the workbook without saving changes
          //and quit Microsoft Excel.
          objBook.Close(COleVariant((short)FALSE), VOptional, VOptional);
          objApp.Quit();
    					
  5. ????????? ?? ?????? ????, ?? ??? ??????
  6. ????? ????? ????? ???? A1:C8 ??? ??? ?? ?????? ????? ??? ????????? ???? ????

??????

MFC ?? ????? ?? Microsoft Excel ?? ??????? ?? ???? ??? ???????? ??????? ?? ??? ????? ?????? ?? Microsoft ???????? ??? ????? ?? ??? ????? ???? ?????? ????? ????:
186120??? ?????? ???? ???? ?? ??? ??? ???? ?? Excel ?? ???????? ???? ?? ??? MFC ?? ????? ???? ????
184663???????? ?? MFC ?? ??? ??? Microsoft Excel ?????????? ?? ???????? ???? ????
179706Excel ???????? ?? ?? ?? ????????????? ?????/???????? ???? ?? ??? MFC ?? ????? ???? ????
178781HOWTO: ???????? MFC ?? ?????????? ??????? ?? ????? ?? Excel
178783HOWTO: ?? ???? Microsoft Excel ????? ????? ?? ??? MFC ?? ?????
167668??? VARIANT * ??? ?? SafeArray ?????????? ?? ??????? ???? ?? ??? ???? ????

???

???? ID: 186122 - ????? ???????: 18 ??????? 2011 - ??????: 6.0
???? ???? ???? ??:
  • Microsoft Excel 2000 Standard Edition
  • Microsoft Visual C++ 5.0 Enterprise Edition
  • Microsoft Visual C++ 5.0 Professional Edition
  • Microsoft Excel 2002 Standard Edition
  • Microsoft Excel 97 Standard Edition
??????: 
kbprogramming kbfunctions kbautomation kbhowto kbinterop kbmt KB186122 KbMthi
???? ?????? ????????
??????????: ?? ???? ?? ???? ??????? ?? ????? ?? Microsoft ????-?????? ?????????? ?????? ?????? ???? ??? ??. Microsoft ???? ??? ????-???????? ?? ????-???????? ????? ?????? ?? ???? ???????? ???? ?? ???? ????? ????? ??? ?? ??? ?????? ?? ???? ???? ???? ??? ????? ??. ???????, ????-???????? ???? ????? ???? ???? ???? ???. ?????, ????????, ?????-???? ?? ??????? ?? ???????? ?? ???? ???, ???? ?? ??? ?????? ???? ???? ??? ????? ??? ?? ???? ??. Microsoft ??????? ??? ???? ?? ?????? ?? ??????????, ????????? ?? ??? ?????? ?? ???? ????? ?? ???? ???????? ?? ??? ???? ????? ?? ??? ????????? ???? ??. Microsoft ????-?????? ?????????? ?? ????? ?????? ?? ?? ??? ??.
?????????? ?? ??????? ????????? ??????? ??:186122

??????????? ???

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com