当前位置: 代码迷 >> Informix >> Ole与ActiveX,该怎么解决
  详细解决方案

Ole与ActiveX,该怎么解决

热度:284   发布时间:2016-05-05 08:54:15.0
Ole与ActiveX
  //---------------------------------------------------------------------------


#pragma hdrstop

#include "DExcelBrokerBase.h"

//---------------------------------------------------------------------------
//构造函数
//只读、只写、读写都可以
DExcelBrokerBase::DExcelBrokerBase( const AnsiString &sFilePath, const EConType eType )
{
    switch( eType )
    {
        case EXCRead:
            s_gFileReadPath = sFilePath;
            break;
        case EXCWrite:
            s_gFileWritePath = sFilePath;
            break;
        case EXCAll:
            s_gFileReadPath = sFilePath;
            s_gFileWritePath = sFilePath;
            break;
        default:
            break;
    }
}

//---------------------------------------------------------------------------
//读写同时
DExcelBrokerBase::DExcelBrokerBase( const AnsiString &sFileReadPath, const AnsiString &sFileWritePath )
{
    s_gFileReadPath     = sFileReadPath;
    s_gFileWritePath    = sFileWritePath;
}


//---------------------------------------------------------------------------
//析构函数
DExcelBrokerBase::~DExcelBrokerBase()
{
    
    //
    if ( !v_gEReadApp.IsEmpty() )
    {
        CloseReadObj();
        v_gEReadApp    = NULL;
    }
    if ( !v_gEReadCell.IsEmpty() )
    {
        v_gEReadCell.Clear();
        v_gEReadCell        = NULL;
    }
    if ( !v_gEReadSheet.IsEmpty() )
    {
        v_gEReadSheet.Clear();
        v_gEReadSheet       = NULL;
    }

    if ( !v_gEReadSingleBook.IsEmpty() )
    {
        v_gEReadSingleBook.Clear();
        v_gEReadSingleBook  = NULL;
    }

    if ( !v_gEReadAllBooks.IsEmpty() )
    {
         v_gEReadAllBooks.Clear();
         v_gEReadAllBooks    = NULL;
    }
    
    //
    if ( !v_gEWriteApp.IsEmpty() || !v_gEWriteSingleBook.IsEmpty() )
    {
        CloseWriteObj();
        v_gEWriteSingleBook = NULL;
        v_gEWriteApp        = NULL;
    }

    if ( !v_gEWriteCell.IsEmpty() )
    {
        v_gEWriteCell.Clear();
        v_gEWriteCell       = NULL;
    }
    if ( !v_gEWriteSheet.IsEmpty() )
    {
        v_gEWriteSheet.Clear();
        v_gEWriteSheet      = NULL;
    }
    if ( !v_gEWriteAllBooks.IsEmpty() )
    {
        v_gEWriteAllBooks.Clear();
        v_gEWriteAllBooks   = NULL;
    }

}

///////////////////////////////////////////////////////////////////////////
//创建OLE对象
int DExcelBrokerBase::CreateExcReadObj()
{
    try
    {
        v_gEReadApp = CreateOleObject("Excel.Application");
    }
    catch( Exception &E )
    {
        s_gErrMsg   = " 创建OLE对象失败!";
  相关解决方案