📄 excelexportmanage.cpp
字号:
// ExcelExportManage.cpp: implementation of the CExcelExportManage class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "ExcelExportManage.h"
#include <comcat.h>
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
CATID CATID_RdExcelExportCategory=__CATALOGID__;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CExcelExportManage::CExcelExportManage()
{
m_bKeepInMemory = FALSE;
}
CExcelExportManage::~CExcelExportManage()
{
DeleteAll();
}
BOOL CExcelExportManage::DoCommand(RDINTERFACELib::ICommandPtr pCommand,int nSubType)
{
if(pCommand == NULL)return FALSE;
try{
if(nSubType>=0)
{
RDINTERFACELib::ICommandSubTypePtr pSubType = pCommand;
if(pSubType)
{
pSubType->SetSubType(nSubType);
}
}
pCommand->Export();
}
catch (...) {
return FALSE;
}
return TRUE;
}
RDINTERFACELib::ICommandPtr CExcelExportManage::FindCommandByDescription(CString sDescription,long& nSubType)
{
long n = GetSize();
for(long i=0;i<n;i++)
{
AddInModel* m = GetAt(i);
if(m->m_sDescription == sDescription)
{
try
{
RDINTERFACELib::ICommandPtr c(m->m_clsid);
nSubType = m->m_nSubType;
return c;
}
catch (...) {
return NULL;
}
}
}
return NULL;
}
RDINTERFACELib::ICommandPtr CExcelExportManage::FindCommandByName(CString sName,long& nSubType)
{
long n = GetSize();
for(long i=0;i<n;i++)
{
AddInModel* m = GetAt(i);
if(m->m_sName == sName)
{
try
{
RDINTERFACELib::ICommandPtr c(m->m_clsid);
nSubType = m->m_nSubType;
return c;
}
catch (...) {
return NULL;
}
}
}
return NULL;
}
RDINTERFACELib::ICommandPtr CExcelExportManage::FindCommandByID(long nID,long& nSubType)
{
long n = GetSize();
for(long i=0;i<n;i++)
{
AddInModel* m = GetAt(i);
if(m->m_nID == nID)
{
try
{
if(m->m_spCommand)
{
RDINTERFACELib::ICommandPtr c = m->m_spCommand;
nSubType = m->m_nSubType;
return c;
}
else
{
RDINTERFACELib::ICommandPtr c(m->m_clsid);
nSubType = m->m_nSubType;
return c;
}
}
catch (...) {
return NULL;
}
}
}
return NULL;
}
void CExcelExportManage::SetKeepInMemory(BOOL bKeep)
{
m_bKeepInMemory = bKeep;
}
BOOL CExcelExportManage::DoCommandByID(long nID)
{
long nSubType = -1;
RDINTERFACELib::ICommandPtr c = FindCommandByID(nID,nSubType);
return DoCommand(c,nSubType);
}
BOOL CExcelExportManage::DoCommandByName(CString sName)
{
long nSubType = -1;
RDINTERFACELib::ICommandPtr c = FindCommandByName(sName,nSubType);
return DoCommand(c,nSubType);
}
BOOL CExcelExportManage::DoCommandByDescription(CString sDescription)
{
long nSubType = -1;
RDINTERFACELib::ICommandPtr c = FindCommandByDescription(sDescription,nSubType);
return DoCommand(c,nSubType);
}
CString CExcelExportManage::GetLastErrorMsg()
{
return m_sLastErrorMsg;
}
void CExcelExportManage::DeleteAll()
{
long n = GetSize();
for(long i=0;i<n;i++)
{
AddInModel* pAddInModel = GetAt(i);
if(pAddInModel->m_spCommand)
{
pAddInModel->m_spCommand->Release();
pAddInModel->m_spCommand = NULL;
}
delete pAddInModel;
}
RemoveAll();
}
BOOL CExcelExportManage::AddCommand(RDINTERFACELib::ICommandPtr& pCommand,CLSID& clsid,long& nComandID,long nSubType,void* param)
{
if(pCommand == NULL)return FALSE;
try
{
pCommand->Create((LONG)param);
BSTR bsDescription = pCommand->Description;
CString sDescription = bsDescription == NULL ? "" : (_bstr_t)bsDescription;
BSTR bsName = pCommand->Name;
CString sName = bsName == NULL ? "" : (_bstr_t)bsName;
AddInModel* pAddInModel = new AddInModel;
pAddInModel->m_spCommand = NULL;
Add(pAddInModel);
pAddInModel->m_clsid = clsid;
pAddInModel->m_sDescription = sDescription;
pAddInModel->m_sName = sName;
pAddInModel->m_nSubType = nSubType;
pAddInModel->m_nID = nComandID++;
if(m_bKeepInMemory)
{
pAddInModel->m_spCommand = pCommand;
pAddInModel->m_spCommand->AddRef();
}
}
catch (...) {
return FALSE;
}
return TRUE;
}
BOOL CExcelExportManage::EnumClassesOfCategories(void * param)
{
BOOL bResult = TRUE;
try
{
ICatInformationPtr pICatInformation(CLSID_StdComponentCategoriesMgr);
IEnumCLSID* pIEnumCLSID = NULL ;
HRESULT hr = pICatInformation->EnumClassesOfCategories(1, &CATID_RdExcelExportCategory, 0, NULL, &pIEnumCLSID) ;
ASSERT(SUCCEEDED(hr)) ;
long nComandID = _BASE_COMMAND_ID_;
CLSID clsid ;
while ((hr = pIEnumCLSID->Next(1, &clsid, NULL)) == S_OK)
{
try
{
RDINTERFACELib::ICommandPtr pCommand(clsid);
RDINTERFACELib::ICommandSubTypePtr pSubType = pCommand;
if(pSubType)
{
long nTotalSub = pSubType->GetCount();
if(nTotalSub>1)
{
for(long nSubNo=0;nSubNo<nTotalSub;nSubNo++)
{
pSubType->SetSubType(nSubNo);
if(!AddCommand(pCommand,clsid,nComandID,nSubNo,param))
bResult = FALSE;
}
}
else
{
if(!AddCommand(pCommand,clsid,nComandID,-1,param))
bResult = FALSE;
}
}
else
{
if(!AddCommand(pCommand,clsid,nComandID,-1,param))
bResult = FALSE;
}
}catch (...) {
m_sLastErrorMsg = "ICatInformation枚举某个组件时失败!";
bResult = FALSE;
continue;
}
}
}
catch(...){
m_sLastErrorMsg = "ICatInformation创建失败!";
return FALSE;
}
return bResult;
}
void CExcelExportManage::AppendNameToMenu(CMenu* pMenu)
{
int n = GetSize();
for(int i=0;i<n;i++)
{
AddInModel* m = GetAt(i);
pMenu->AppendMenu(MF_STRING, m->m_nID, m->m_sName);
}
}
void CExcelExportManage::AppendDescriptsToMenu(CMenu* pMenu)
{
int n = GetSize();
for(int i=0;i<n;i++)
{
AddInModel* m = GetAt(i);
pMenu->AppendMenu(MF_STRING, m->m_nID, m->m_sDescription);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -