vc6.0呼叫excel xp,word 2k (轉)

worldblog發表於2007-08-17
vc6.0呼叫excel xp,word 2k (轉)[@more@]

#include
#include
#pragma warning (disable:4146 4192 4786 4081)
#define USE_1

#ifdef USE_OFFICEXP
#import "C:Program FilesCommon Files SharedOffice10MSO.DLL"
#import "c:Program FilesCommon FilesMicrosoft SharedVBAVBA6VBE6EXT.olb"
#import "c:Program FilesMicrosoft OfficeOffice10MS.olb" rename("Exit","ExitWindowsEx")
#import "c:Program FilesMicrosoft OfficeOffice10.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::ionPtr 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的問題。於是寫了一下。寫完了再儲存。順便發一下。這可是原創的哈。好想有三顆星星了。


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10752043/viewspace-963035/,如需轉載,請註明出處,否則將追究法律責任。

相關文章