自已写成类吧。不用控件。下面是我用CB写的,不是很全。但愿对你会有帮助。
#ifndef OperateWord2kH
#define OperateWord2kH
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include "vcl/utilcls.h"
class OperateWord
{
protected:
Variant WordApp,Document;
public:
OperateWord(){}
~OperateWord(){};
Variant & wordApp(){return WordApp;}
Variant & document(){return Document;}
public:
virtual void OpenWord();
virtual void OpenWordFile(AnsiString str_ExcelFileName,bool Visibled=true,bool IfReadOnly=false);
virtual void DocumentSave(); //存盘当前路径
virtual void DocumentSaveAs(AnsiString str_FileName); //文件另存
virtual void DocumentClose();
virtual void QuitWord(); //关闭文件
};
#endif
//以上为头文件
#include <vcl.h>
#pragma hdrstop
#include "OperateWord2k.h"
/*
WordApp=CreateOleObject("Word.Application");
//使Excel 显示
WordApp.OlePropertySet ("visible",true);
//创建 Workbooks
Documents=WordApp.OlePropertyGet("Documents");
//显示
AnsiString FileName=ThisPath.Trim()+EXCHANGE+adoTBlobBiaoHao->Value.Trim ()+EXT;
Document=Documents.OleFunction("Open",FileName);//
*/
void OperateWord::OpenWord()
{
WordApp=CreateOleObject("Word.Application");
WordApp.OlePropertySet ("visible",true);
Document=WordApp.OlePropertyGet("ActiveWorkBook");
}
void OperateWord::OpenWordFile(AnsiString str_ExcelFileName,bool Visibled,bool IfReadOnly)
{
WordApp=CreateOleObject("Word.Application");
WordApp.OlePropertyGet("Documents").OleProcedure("Open",str_ExcelFileName,NULL,IfReadOnly);
WordApp.OlePropertySet ("visible",Visibled);
Document=WordApp.OlePropertyGet("ActiveDocument");
}
void OperateWord:
ocumentSave()
{
Document.OleProcedure("Save");
}
void OperateWord:
ocumentSaveAs(AnsiString str_FileName)
{
Document.OleProcedure("Close",str_FileName);
}
void OperateWord:
ocumentClose()
{
Document.OleProcedure("Close");
}
void OperateWord::QuitWord()
{
if(!WordApp.IsEmpty())
WordApp.OleProcedure("Quit") ;
}
//以上为类的实现