??? ?????? ???? ???? ?? ??? ??? ???? ?? Excel ?? ???????? ???? ?? ??? MFC ?? ????? ???? ????

???? ?????? ???? ??????
???? ID: 186120 - ?? ???????? ?? ?????? ??? ?? ?? ???? ???? ???? ??.
??? ?? ??????? ???? | ??? ?? ??????? ????

?? ????? ??

??????

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

???? ???????

?????? ?? ??-??-?? populating ???? ???? multi-cell ?????? ?? ????, two-dimensional variant SAFEARRAY ?? ?? ???? ??? ???? ?? ??? Excel ?????? ???????? ?? ??? SetValue ?????? ?? ??? ?? ????? ????? ????? ????? ?? ???? illustrate ?? ????????? ???

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. ??? 1 ?? 12 ??? ????? ???? ?? Microsoft ???????? ??? ????? ?? ????? IDispatch interfaces ?? ????? ?????? Excel8.olb ?????? ????????? ??? ????????? ????? ????????? ????? ?? ??? ?? ???? ????:
    178749MFC ?? ?? ?????? ????????? ?? ????? ??????? ????????? ????? ???? ????
  2. ????? ????? ??? ???? ?? ??? 4 ?? 5 ?????? ????178749, ??? ?? ??? ????? ???????? ?? ????????? ?? ??? ??? ??????? ?? ??????? ????? ?? ??????:
                                      Member                Member
          Control   Name              Variable Type         Variable Name
          -----------------------------------------------------------------
          Edit      IDC_STARTINGCELL  m_sStartingCell       CString
          Edit      IDC_NUMROWS       m_iNumRows            short
          Edit      IDC_NUMCOLS       m_iNumCols            short
          CheckBox  IDC_STRING        m_bFillWithStrings    BOOL
    					
  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 range;
    
          if(!UpdateData(TRUE))
          {
             return;
          }
    
          // Instantiate Excel and start a new workbook.
          objApp.CreateDispatch("Excel.Application");
          objBooks = objApp.GetWorkbooks();
          objBook = objBooks.Add(VOptional);
          objSheets = objBook.GetWorksheets();
          objSheet = objSheets.GetItem(COleVariant((short)1));
    
          //Get the range where the starting cell has the address
          //m_sStartingCell and it's dimensions are m_iNumRows x m_iNumCols.
          range = objSheet.GetRange(COleVariant(m_sStartingCell),
                                    COleVariant(m_sStartingCell));
          range = range.GetResize(COleVariant(m_iNumRows),
                                  COleVariant(m_iNumCols));
    
          //*** Fill the range with an array of values.
    
          //Create the SAFEARRAY.
          COleSafeArray saRet;
          DWORD numElements[2];
          numElements[0]= m_iNumRows;   //Number of rows in the range.
          numElements[1]= m_iNumCols;   //Number of columns in the range.
    
          if(m_bFillWithStrings)
          {
             saRet.Create(VT_BSTR, 2, numElements);
          }
          else
          {
             saRet.Create(VT_R8, 2, numElements);
          }
    
          //Fill the SAFEARRAY.
          long index[2];
          long iRow;
          long iCol;
    
          for(iRow=0;iRow<=m_iNumRows-1;iRow++)
          {
             for(iCol=0;iCol<=m_iNumCols-1;iCol++)
             {
                index[0] = iRow;
                index[1] = iCol;
                if(m_bFillWithStrings)      //Fill with Strings.
                {
                   VARIANT v;
                   CString s;
                   VariantInit(&v);
                   v.vt = VT_BSTR;
                   s.Format("r%dc%d", iRow, iCol);
                   v.bstrVal = s.AllocSysString();
                   saRet.PutElement(index, v.bstrVal);
                   SysFreeString(v.bstrVal);
                   VariantClear(&v);
                }
                else                     //Fill with Numbers.
                {
                   double d;
                   d = (iRow*1000) + iCol;
                   saRet.PutElement(index, &d);
                }
             }
          }
    
          //Set the range value to the SAFEARRAY.
          range.SetValue(COleVariant(saRet));
          saRet.Detach();
    
          //Return control of Excel to the user.
          objApp.SetVisible(TRUE);
          objApp.SetUserControl(TRUE);
    					
  5. ?????? ????, ?? ????????? ?? ??????
  6. ????? ????? ?? ???????? ???? ?? ??? ????? ??? ????????? ????:
          Control               Contents
          ------------------------------
          IDC_STARTINGCELL      A1
          IDC_NUMROWS           10
          IDC_NUMCOLS           5
          IDC_STRING            True
    						
    ??? ????? ?????

    ??????: ??? ?? ????????????? ????? ??, ?? ???????? ??? ?? ??? ???? ?????????? ?? ???? A1:E10 ????????? ???
  7. ????? ????? ?? ???????? ???? ?? ??? ????? ??? ????????? ????:
          Control               Contents
          ------------------------------
          IDC_STARTINGCELL      C3
          IDC_NUMROWS           2
          IDC_NUMCOLS           9
          IDC_STRING            False
    						
    ??? ????? ?????

    ??????: ??? ?? ????????????? ????? ??, ?? ???????? ??? ?? ???? ?????????? ?? ???? C3:K4 ????????? ???

??????

MFC ?? ????? ?? Microsoft Excel ?? ??????? ?? ???? ??? ???? ??????? ?? ??? ????? ????? ?????? ?? Microsoft ???????? ??? ?????:
186122Excel ???????? ?? ?? ?????? ?? ??? ???? ?? ??????? ???? ?? ??? MFC ?? ????? ???? ????

184663???????? ?? MFC ?? ??? ??? Microsoft Excel ?????????? ?? ???????? ???? ????

179706Excel ???????? ?? ?? ?? ????????????? ?????/??????? ?? ??? MFC ?? ????? ????

178781MFC ?? ?????????? ??????? ?? ????? ?? Excel ?? ???????? ???? ?? ??? ???? ????

178783???? Microsoft Excel ????? ????? ?? ??? MFC ?? ????? ???? ????

???

???? ID: 186120 - ????? ???????: 02 ?????? 2010 - ??????: 4.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
??????: 
kbautomation kbcode kbhowto kbinterop kbmt KB186120 KbMthi
???? ?????? ????????
??????????: ?? ???? ?? ???? ??????? ?? ????? ?? Microsoft ????-?????? ?????????? ?????? ?????? ???? ??? ??. Microsoft ???? ??? ????-???????? ?? ????-???????? ????? ?????? ?? ???? ???????? ???? ?? ???? ????? ????? ??? ?? ??? ?????? ?? ???? ???? ???? ??? ????? ??. ???????, ????-???????? ???? ????? ???? ???? ???? ???. ?????, ????????, ?????-???? ?? ??????? ?? ???????? ?? ???? ???, ???? ?? ??? ?????? ???? ???? ??? ????? ??? ?? ???? ??. Microsoft ??????? ??? ???? ?? ?????? ?? ??????????, ????????? ?? ??? ?????? ?? ???? ????? ?? ???? ???????? ?? ??? ???? ????? ?? ??? ????????? ???? ??. Microsoft ????-?????? ?????????? ?? ????? ?????? ?? ?? ??? ??.
?????????? ?? ??????? ????????? ??????? ??:186120

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

 

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