vc6.0调用excel xp,word 2k

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

#ifdef USE_OFFICEXP
#import "C:/Program Files/Common Files/Microsoft Shared/Office10/MSO.DLL"
#import "c://Program Files//Common Files/Microsoft Shared/VBA/VBA6/VBE6EXT.olb"
#import "c:/Program Files/Microsoft Office/Office10/MSWORD.olb" rename("ExitWindows","ExitWindowsEx")
#import "c:/Program Files/Microsoft Office/Office10/excel.exe" rename("DialogBox", "DialogBoxXL") rename("RGB", "RBGXL") /
         rename("DocumentProperties", "DocumentPropertiesXL") exclude("IFont","IPicture")
#else
#import "c:/Program Files/Microsoft Office/Office/MSO9.dll"
#import "C:/Program Files/Common Files/Microsoft Shared/VBA/VBA6/VBE6EXT.OLB" no_namespace
#import "c:/Program Files/Microsoft Office/Office/MSWORD9.OLB" rename("ExitWindows","_ExitWindows")
#import "c:/Program Files/Microsoft Office/Office/excel9.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/n",iColCnt);
 int iRowCnt = pRange ->GetRows() ->GetCount();
 printf("used rows  is %d/n",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的问题。于是写了一下。写完了再保存。顺便发一下。这可是原创的哈。好想有三颗星星了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值