VC 2005 调用excel 2003

#include <iostream>

#import "C:\Program Files\Common Files\Microsoft Shared\office11\mso.dll" rename("DocumentProperties", "DocumentPropertiesXL") rename("RGB", "RBGXL")

#import "C:\Program Files\Common Files\Microsoft Shared\VBA\VBA6\vbe6ext.olb"

#import "C:\Program Files\Microsoft Office\Office11\EXCEL.EXE" rename("DialogBox", "DialogBoxXL") rename("RGB", "RBGXL") rename("DocumentProperties", "DocumentPropertiesXL") rename("ReplaceText", "ReplaceTextXL") rename("CopyFile", "CopyFileXL") no_dual_interfaces

using namespace std;

int main()

{

     CoInitialize(NULL);

     // Create app

     Excel::_ApplicationPtr mpXL;

     mpXL.CreateInstance(L"Excel.Application");

      

     mpXL->DisplayAlerts =false;

     Excel::_WorkbookPtr pBook  = mpXL->Workbooks->Add();

     Excel::_WorksheetPtr sheet=pBook->ActiveSheet;

     Excel::RangePtr range = sheet->Cells;

     range->Item[1][1]="row1,col1";

     range->Item[1][2]="row1,col2";

 

     mpXL->Visible=true;

 

     CoUninitialize();

     

     return 0;

}

 

 

参考文章:

C++ – Use Excel from c++ (Qt) ActiveX

http://berenger.eu/blog/2010/11/15/c-use-excel-from-c-qt-activex/

VC2005自动化Excel2003的编译错误问题 

http://huigezrx.blog.163.com/blog/static/32101652201028104937279/

posted @ 2011-10-18 13:18  网络小虫  阅读(1057)  评论(0编辑  收藏  举报