程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> VC >> vc教程 >> vc6.0調用excel xp,word 2k

vc6.0調用excel xp,word 2k

編輯:vc教程

#include <ole2.h>
#include <stdio.h>
#pragma warning (disable:4146 4192 4786 4081)
#define USE_OfficeXP 1

#ifdef USE_OfficeXP
#import "C:Program FilesCommon FilesMicrosoft SharedOffice10MSO.DLL"
#import "c:\Program Files\Common FilesMicrosoft SharedVBAVBA6VBE6EXT.olb"
#import "c:Program FilesMicrosoft OfficeOffice10MSWord.olb" rename("ExitWindows","ExitWindowsEx")
#import "c:Program FilesMicrosoft OfficeOffice10Excel.exe" rename("DialogBox", "DialogBoxXL") rename("RGB", "RBGXL")
         rename("DocumentProperties", "DocumentPropertIEsXL") exclude("IFont","IPicture")
#else
#import "c:Program FilesMicrosoft OfficeOfficeMSO9.dll"
#import "C:Program FilesCommon FilesMicrosoft SharedVBAVBA6VBE6EXT.OLB" no_namespace
#import "c:Program FilesMicrosoft OfficeOfficeMSWord9.OLB" rename("ExitWindows","_ExitWindows")
#import "c:Program FilesMicrosoft OfficeOfficeExcel9.olb" rename("DialogBox", "DialogBoxXL") rename("RGB", "RBGXL")
         rename("DocumentProperties", "DocumentPropertIEsXL") exclude("IFont","IPicture")
#endif
int main(int argc, char* argv[])
{
 VARIANT varItem;
 varItem.vt = VT_I4;
 varItem.intVal = 1;
    ::CoInitialize(NULL);
    CLSID clsid;
   
#if 0
 CLSIDFromProgID(L"Word.Application", &clsid);
 Word::_ApplicationPtr pApp;
 pApp.CreateInstance (clsid,NULL);
 pApp ->PutVisible (VARIANT_TRUE);
 pApp ->GetDocuments() ->Add();
 Word::_DocumentPtr pWordDocument =pApp-> GetActiveDocument();
 Word::SelectionPtr pSelection    = pApp ->GetSelection();
 pSelection ->TypeText("badguy");
#endif
#if 1
 CLSIDFromProgID(L"Excel.Application", &clsid);
 Excel::_ApplicationPtr pApp;
 pApp .CreateInstance (clsid,NULL);
 pApp ->PutVisible (0,VARIANT_TRUE);
 Excel::_WorkbookPtr pWorkbook = pApp ->GetWorkbooks () ->Add ();
 Excel::_WorksheetPtr    pSheet    = pWorkbook ->GetWorksheets ()  ->GetItem (varItem);
 Excel::RangePtr     pRange    = pSheet ->GetUsedRange(0);
 int iColCnt = pRange ->GetColumns() ->GetCount();
 printf("used columns is %d ",iColCnt);
 int iRowCnt = pRange ->GetRows() ->GetCount();
 printf("used rows  is %d ",iRowCnt);
 pRange = pSheet ->GetRange(OLESTR("A1"));
 pRange ->Value2     = OLESTR("SOME");
 Excel::InteriorPtr  pInterior= pRange ->GetInterior ();
 varItem.intVal = 0xff0000;
 pInterior ->PutColor (varItem);
 pSheet ->PrintPrevIEw ();
#endif
    ::CoUninitialize();
    return 0;
}

好久沒回復貼子,今天看到一個Excel的問題。於是寫了一下。寫完了再保存。順便發一下。這可是原創的哈。好想有三顆星星了。

  1. 上一頁:
  2. 下一頁:
欄目導航
Copyright © 程式師世界 All Rights Reserved