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

?????? ????????? ?????? ?????????
???? ???????: 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 ??????. ????? ????????? ??????? ?? ??? ??????? ??? ??? ??? ???? Visual C++ ????????? ????????.
????? ???? | ?? ????

?? ??? ??????

??????

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

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

?????? ???? multi-cell ??? ??? ??????? ???? ?? ??? ????? ????? ??????? ???? ?????? ???? ??? ???? ????? ???????. ???????? ????? ??????? ???? ????? ??????? ?? ??? ????? ?????? ???? ????? ???????? ??????? ????. ???? ??????? ??????? ??? ??????? ??? ????? ? ??????? ???????? ???????? ????? ?????? ???????.
  1. ???? ??????? ???????? ?? ??? "????? ???? ?????" ?? ????? ????? ??????? ?????? ???? ??????? ?????:
    307473????? ??????? ????? ??? ?? Office ??????? ?? Visual C++ .NET
    ?? ?????? 3? ????? ?? ???? ????? ?????? ??? ???????. ????? ????? ???? ??? IDC_GETVALUES ???????? ????????? ??? ????? ?????. ????? ????? ???? ???????? ??? IDC_CHECK ???????? ????????? ??? ????? ?? ?????.

    ?? ?????? 4 ?? ??????? ??? "????? ?????? 10.0 Excel Microsoft" ??? ?? ????? Excel 2002 ?? Office XP. ?????? ????????? ?? Excel 2002 ?? Office\Office10\Excel.exe Files\Microsoft C:\Program. ?? ??? "????? ?????? 11.0 Excel Microsoft" ??? ?? ????? Microsoft Office Excel 2003. ?????? ????????? ?? Excel 2003 ?? Office\Office11\Excel.exe Files\Microsoft C:\Program. ????? ???????? Microsoft Excel ???????:
    • _Application
    • _Workbook
    • _Worksheet
    • ????
    • ????????
    • ????? ?????
    ?? ?????? 6 ????? ?????? ????? # ??????? ?????? ??? ??????? & # pragma ??? ????? ?? 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
    }
    					
    ??:
    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));
    }
    					
    ?????? ?? Visual C++ 2005 ??? ????? ??????? ??? ??? ??????? ??? ?????? ??????? ??????? ?????? (/ clr:oldSyntax) ????? ????? ????????? ???????? ?????? ?????. ?????? ??????? ??? ??? ??????? ??? ?????? ??????? ??????? ?????? ???? ??????? ???????:
    1. ???? ??? ??????? ?? ???? ??? ????? ProjectName.

      ??????ProjectName ?????? ?????? ??? ???????.
    2. ?? ?????? ????? ????? ?? ???? ??? ???.
    3. ?? ????? ??????? ???? ?????? ??? ????? ????? ?????? ??? ? ?????? ??????? (/ clr:oldSyntax) ?? ??? ????? ????? ?????? ???? ????? ??????? ???????.
    4. ???? ??? ????? ? ?? ???? ??? ?????.
    ?????? ??? ???? ?? ????????? ??? ??? ????? ????? ?????? ?????? ?????? ??????? ??????? ??? ?? ?????? ???? ?????? Microsoft Network (MSDN) ?????? ??? ?????:
    http://msdn2.microsoft.com/en-us/library/k8d11d4s.aspx
    ??? ??????? ????? ??????? ???????.
  5. ?????? ??? ???? ?????? ????? ????? ??????? ??? ????? ???. ??????? ???????? ???????? ???????
    void CAutoProjectDlg::OnBnClickedGetvalues()
    {
    	// TODO: Add your control notification handler code here
    }
    					
    ??:
    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 ??????? ?? ???? ????? ?????? ?? ???????? ??????? ?? ????.
  3. ???? ??? ?????? ??? ???. ???????? ???????? ???????? ?? ??????? A1:E5 ??? ???? ???? ????? ??????? ?? ???? ?????.
  4. ??? ????? ???????? ????? ?? ???? ??? "?????" ?????? ??????? A1:E5 ?????? ?????.
  5. ???? ??? ????? ??? ??? ??? ??????? ?? ???? ?????.

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

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

?????

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

???????

???? ???????: 308407 - ????? ??? ??????: 27/?? ?????/1427 - ??????: 6.3
????? ???
  • Microsoft Visual C++ 2005 Express Edition
  • Microsoft Visual C++ .NET 2003 Standard Edition
  • Microsoft Visual C++ .NET 2002 Standard Edition
  • Microsoft Office Excel 2003
  • Microsoft Excel 2002 Standard Edition
????? ??????: 
kbmt kbautomation kbhowtomaster KB308407 KbMtar
????? ????
???: ??? ????? ??? ?????? ???????? ?????? ????? ???? ????? ?????????? ????? ?? ????????? ?????? ????. ???? ???? ?????????? ???? ?? ???????? ???????? ?????? ????????? ????? ????????? ???????? ????? ???????? ?????? ?? ?????? ??? ?? ???????? ???????? ?? ????? ??????? ?????? ??? ??????? ?????? ??. ?????? ?? ???? ??? ??????? ???????? ????? ?? ???? ????? ?????? ??? ????? ??? ????? ??????? ?? ????? ?? ?????? ??? ??? ??????? ??????? ?? ????? ????? ????? ????? ?????. ?? ????? ???? ?????????? ??????? ??? ????? ?? ??????? ?? ????? ?????? ?? ??? ????? ?? ????? ??????? ?? ???????? ?? ??? ???????. ???? ???? ?????????? ???????? ??? ????? ?????? ??????? ??????
???? ??? ????? ??????? ?????? ??????????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