??? ?? ?????? ???????? ?? ????? ?? ???? ?? ??????? ???? ?? ??? MFC ?? ????? C++ 2005 ?? Visual C++ .NET ?? Excel ?? ???????? ???? ?? ??? ???? ????

???? ?????? ???? ??????
???? ID: 308407 - ?? ???????? ?? ?????? ??? ?? ?? ???? ???? ???? ??.
???? Microsoft C# .NET ??????? ?? ??? ?? ???? ??, ?????302096.
?? ???? ?? Microsoft Visual Basic .NET ??????? ?? ???, ?????302094.
???:Microsoft Visual C++ 2005, Microsoft Visual C++ .NET 2003, ?? Microsoft Visual C++ .NET 2002 Microsoft .NET Framework ?????? ??? ?? ??? ?? ???????? ???? ?? ????????? ??? Microsoft Windows ??? ???? ?? ??? ??????? ?? ???? ??? ?? ?? ??????? ???? ????????? C++ ????? ?? ??? ???? ????
??? ?? ??????? ???? | ??? ?? ??????? ????

?? ????? ??

??????

?? ??? ?? ??? ???? ????????? ???? ?? ?? Microsoft Excel ?? ???? ?? ???????? ?? ????? ?? ???? multi-cell ?????? ?? ????? ?? ??????? ???? ?? ??? ????? C++ 2005 ?? Visual C++ .NET ?? ???????? ???? ?? ??? ???? ?????

Excel ?? ??? ??? ??????? ??????? ?????

?? ??? ??? ?? ???? ?? populating ???? ???? multi-cell ?????? ?? ????, ?? ??? ?? ??? ?? ???? ???Value:?? ??? ?????????????????? ???? two-dimensional ???? ?? ??? ??? Likewise, ?? ?? ???? ??? ??????? two-dimensional ???? ??? ?? ?? ???? ?????? ?? ??? ??? ?? ??? ??? ?? ????? ??Value:???? ????? ????? ?? ???? demonstrate ?? ????????? ?? ??? ?? ??? ?? ?? ????? two-dimensional ???????? ?? ????? ?? ???? ?? ???????????? ???? ?? ??? ???
  1. ???? ??? ??????? ??????? ?? ????? ?? ??? ????? Microsoft ???????? ???? ?? "???? ??????? ??????? ?????" ??? ??? ??? ????? ?? ???? ????:
    307473????? C++ .NET ?? ??????? ?? Office ?? ??? ??? ?????? ????????? ?? ????? ???? ????
    ??? 3, ??? ?????? ?? ????? ??? ?? ???? ??? ????? ???????? ???? ?? ??? ??? ?? ID ????????? ????IDC_GETVALUES?? ???? ?? ??? ????????? ??????? ????. ???? ?? ??? ??? ????? ?? ID ????????? ????IDC_CHECK?? ???? ?? ??? ???????????????? ?? ??? ???.

    ??? 4 ??? ?? ???? ??, ??? Excel 2002 ?? Office XP ??????? "Microsoft Excel 10.0 ???????? ?????????" ?????? Excel 2002 ?? ??? ??????? ????? ?? C:\Program Files\Microsoft Office\Office10\Excel.exe ??? ??, ??? ?? Microsoft Office Excel 2003 ??????? ??? "Microsoft Excel 11.0 ???????? ?????????" ?? ??? ????? Excel 2003 ?? ??? ??????? ????? ?? C:\Program Files\Microsoft Office\Office11\Excel.exe ??? ????? Microsoft Excel ???????? ?? ??? ????:
    • _Application
    • _Workbook
    • _Worksheet
    • ??????
    • ?????????????
    • ??????????
    ??? 6, ??? ??? ??????# ????? ?????? ??? ???? ????? ??? #pragmadirective Autoprojectdlg.h:
    #include "CApplication.h"
    #include "CRange.h"
    #include "CWorkbook.h"
    #include "CWorkbooks.h"
    #include "CWorksheet.h"
    #include "CWorksheets.h"
    					
  2. ????? ?? ????????? ????? ?? ?? ??? ??????CAutoProjectDlg????:
    CApplication oExcel;
    CWorkbook oBook;
    					
  3. ???? ????? ????? ???, ?? ???? ?????IDC_CHECK?? ?? ??? ?????? ??????. ?????????? m_bFillWithStrings ??? ?? ????? ??????????.
  4. ???-????? ?? ???? ????? ????? ???, ??????????? ????? ??? ?? ???????????? ????
    void CAutoProjectDlg::OnBnClickedRun()
    {
    	// TODO: Add your control notification handler code here
    }
    					
    with::
    void CAutoProjectDlg::OnBnClickedRun()
    {
    	CWorkbooks oBooks;
    	CWorksheets oSheets;
    	CWorksheet oSheet;
    	CRange oRange;
    	COleVariant covOptional(DISP_E_PARAMNOTFOUND,VT_ERROR);
    
    	// If you have not created Excel, create a new instance.
    	if (oExcel.m_lpDispatch == NULL) {
    		oExcel.CreateDispatch("Excel.Application");
    	}
    	// Show Excel to the user.
    	oExcel.put_Visible(TRUE);
    	oExcel.put_UserControl(TRUE);
    
    	// Add a new workbook and get the first worksheet in that book.
    	oBooks = oExcel.get_Workbooks();
    	oBook = oBooks.Add(covOptional);
    	oSheets = oBook.get_Worksheets();
    	oSheet = oSheets.get_Item(COleVariant((short)1));
    
    	// Get a range of data.
    	oRange = oSheet.get_Range(COleVariant("A1"),covOptional);
    	oRange = oRange.get_Resize(COleVariant((short)5),COleVariant((short)5));
    
    	COleSafeArray saRet;
    	DWORD numElements[2];
    	numElements[0] = 5;
    	numElements[1] = 5;
    
    	long index[2];
    	// Create a BSTR or double safe array.
    	if (m_bFillWithStrings.GetCheck())
    		saRet.Create(VT_BSTR,2,numElements);
    	else
    		saRet.Create(VT_R8,2,numElements);
    
    	// Fill the array with data.
    	for (int iRow = 1; iRow <= 5; iRow++) {
    		for (int iCol = 1; iCol <= 5; iCol++) {
    			index[0]=iRow-1;
    			index[1]=iCol-1;
    			if (m_bFillWithStrings.GetCheck()) {
    				CString szTemp;
    				szTemp.Format("%d|%d",iRow,iCol);
    				BSTR bstr = szTemp.AllocSysString();
    				saRet.PutElement(index,bstr);
    				SysFreeString(bstr);
    			} else {
    				double d = iRow * iCol;
    				saRet.PutElement(index,&d);
    			}
    		}
    	}
    	// Send the array to Excel.
    	oRange.put_Value(covOptional,COleVariant(saRet));
    }
    					
    ???:????? C++ 2005, ??? ?? ??????? ???? ?????? ?????? ??????? ?????? (?????? ??????/clr:oldSyntax) ??????????? ????? ??? ????? ?? ?????? ???? ?? ???? ????? ?? ??? ??????? ???? ?????? ?????? ??????? ??????, ?? ????? ?? ???? ????:
    1. ????? ????,??????????? ????-????? ????, ?? ???? ???ProjectName???.

      ???:ProjectName????????? ?? ??? ?? ??? ?? ??????????? ???
    2. ??????? ??????????????? ????? ????-????? ????, ?? ???? ??????????.
    3. ???? ??? ???, ????? ???? ?? ??? ???? ?? ?????????? ???? ?????? ??????, ?????? ???????? (/ clr:oldSyntax)???????????? ???? ?????? ??????????????? ?????????
    4. ????? ????,???? ?????? ????-????? ????, ?? ???? ???OK.
    ??????? ???? ?????? ?? ???? ??? ???? ??????? ?? ??? ??????? ???????? ?? ?????? ????, ????? Microsoft ?????? ??????? (MSDN) ??? ???? ?? ????:
    HTTP://msdn2.Microsoft.com/en-us/library/k8d11d4s.aspx
    ?? ????? ?? ???? ???? ?? ???? ?????
  5. ???? ????? ????? ?? ????? ?? ???-????? ??????? ??????? ????. ????? ??? ?? ???????????? ????
    void CAutoProjectDlg::OnBnClickedGetvalues()
    {
    	// TODO: Add your control notification handler code here
    }
    					
    with::
    void CAutoProjectDlg::OnBnClickedGetvalues()
    {
    	CWorksheets oSheets;
    	CWorksheet oSheet;
    	CRange oRange;
    	COleVariant covOptional(DISP_E_PARAMNOTFOUND,VT_ERROR);
    
    	// Make sure that Excel has been started.
    	if (oExcel.m_lpDispatch == NULL) {
    		AfxMessageBox("Excel has not been started.  Press button1 to start Excel.");
    		return;
    	}
    	// Get the first worksheet.
    	oSheets = oBook.get_Worksheets();
    	oSheet = oSheets.get_Item(COleVariant((short)1));
    	// Set the range of data to retrieve
       	oRange = oSheet.get_Range(COleVariant("A1"),COleVariant("E5"));
    
    	// Get the data.
    	COleSafeArray saRet(oRange.get_Value(covOptional));
    
            long iRows;
            long iCols;
            saRet.GetUBound(1, &iRows);
            saRet.GetUBound(2, &iCols);
    
    	CString valueString = "Array Data:\r\n";
    	long index[2];
    	// Loop through the data and report the contents.
    	for (int rowCounter = 1; rowCounter <= iRows; rowCounter++) {
    		for (int colCounter = 1; colCounter <= iCols; colCounter++) {
    			index[0]=rowCounter;
    			index[1]=colCounter;		   
    			COleVariant vData;
    			saRet.GetElement(index,vData);
    			CString szdata(vData);
                valueString += szdata;
    			valueString += "\t";		
    		}
    		valueString += "\r\n";
    	}
    	AfxMessageBox(valueString,MB_SETFOREGROUND,NULL);
    }
    					

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

  1. ????? ?? ????? ????????? ?? ????? ?? ??? F5 ??????
  2. ????? ????,?????. ????????? ???? ?? ????????????? ??? Excel ??????? ?? ???? ?? ?? ??? ???? ?? ???????? ???? ?? ???? ?????????? ?? ???? A1:E5 populates ???
  3. ????? ????,??? ??????? ????. ????????? A1:E5 ?? ?????? ??? ???? ?? ???? ?? ???? ??? retrieves ?? ?? ?????? ??? ????? ????? ??? ????????? ???? ???
  4. ??? ?????????????? ?? ??? ????? ????? ????????????? ?? ??? ???????? ???? ?? ??? A1:E5 ?????
  5. ????? ????,??? ??????? ??????? ????? ????? ??? ???????? ??? ????????? ?????

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

??? ?? ????? ?? Excel ???????? ????????? ?? ??? ???? wrappers ???????????????? ?????? ???? ?? TypeLib ??????? ???, ???? ?? ?????? ????? ??? ???? ?? ???????? ????????? ?? ??? ??????? ????? ?? ?????? ?? ????, ?? ??? ????? ?? ??? ??????? ???? ?? ???? ???????? ????????? ?? ??? ???? ?? ?? ????? ??? ???? ????????????? ??????? ?? ???, ???? ?? ???? ?????? ?? ????? ?? ???? ?? Microsoft ???????? ??? ?????::
311408BUG: '????-????' ??????? ?? MFC ???? ?? ????????? ??? ??????
??? ???? ????? ?????? ????? ?? ?? ???? ????? ????????? ?????, ????? "Variant DialogBox" CRange.h ??? "Variant _DialogBox" ???? ?? ???:
C4003 ???????: 'DialogBoxA' ?????? ?? ??? ???????? ???? ???????? ????????
???? ??????? ?? ??? ???? ?? ?????? ??, ????? ???????? ???? ?????:
311407BUG: MFC ??????? Doesn't ????? API ??????? ?? ??? ????? ??????

??????

???? ??????? ?? ???, ????? Microsoft ?????? ????? ??????? (MSDN) ??? ????:
Visual Studio ?? ??? Microsoft Office ??????????
http://msdn2.microsoft.com/en-us/library/aa188489(office.10).aspx
??? ?? ??????? ???? ?? ??? ???????? ?? ????? ???? ?? ???? ??? ???? ??????? ?? ??? Visual Studio ?? ????? ????????? ?? ??? ???? ?? Excel, ????? ???????? ???? ???? ?????:
186120??? ?????? ???? ???? ?? ??? ??? ???? ?? Excel ?? ???????? ???? ?? ??? MFC ?? ????? ???? ????
186122Excel ???????? ?? ?? ?????? ?? ??? ???? ?? ??????? ???? ?? ??? MFC ?? ????? ???? ????
247412???????: Visual Basic ?? Excel ??? ???? ??????????? ???? ?? ??? ???????

???

???? ID: 308407 - ????? ???????: 04 ?????? 2010 - ??????: 2.0
???? ???? ???? ??:
  • Microsoft Visual C++ 2005 Express Edition
  • Microsoft Visual C++ .NET 2003 Standard Edition
  • Microsoft Visual C++ .NET 2002 Standard Edition
  • Microsoft Excel 2002 Standard Edition
??????: 
kbautomation kbhowtomaster kbmt KB308407 KbMthi
???? ?????? ????????
??????????: ?? ???? ?? ???? ??????? ?? ????? ?? Microsoft ????-?????? ?????????? ?????? ?????? ???? ??? ??. Microsoft ???? ??? ????-???????? ?? ????-???????? ????? ?????? ?? ???? ???????? ???? ?? ???? ????? ????? ??? ?? ??? ?????? ?? ???? ???? ???? ??? ????? ??. ???????, ????-???????? ???? ????? ???? ???? ???? ???. ?????, ????????, ?????-???? ?? ??????? ?? ???????? ?? ???? ???, ???? ?? ??? ?????? ???? ???? ??? ????? ??? ?? ???? ??. Microsoft ??????? ??? ???? ?? ?????? ?? ??????????, ????????? ?? ??? ?????? ?? ???? ????? ?? ???? ???????? ?? ??? ???? ????? ?? ??? ????????? ???? ??. Microsoft ????-?????? ?????????? ?? ????? ?????? ?? ?? ??? ??.
?????????? ?? ??????? ????????? ??????? ??:308407

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

 

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