Box", "ignorethis"), rename("VBE", "JOEVBE"), \
rename("ReplaceText", "JOEReplaceText"), rename("CopyFile","JOECopyFile"), \
rename("FindText", "JOEFindText"), rename("NoPrompt", "JOENoPrompt")
using namespace Office;
using namespace VBIDE;
using namespace Excel ;
#define NULLSTR TEXT("")
class CEclOp
{
public:
CEclOp(void);
~CEclOp(void);
public:
BOOL InsertAChart(short nSheet);
BOOL DeleteASheetByNO(short nSheet);
BOOL DeleteASheetByName(CString strSheet);
CString GetCellText(short nSheet, int Row, int Col);
void DeleteCells(short nSheet, CString strRange);
void DeleteCells(short nSheet, unsigned int nFRow, unsigned int nFCol, unsigned int nTRow, unsigned int nTCol);
BOOL Initialization(CString strFilePath = NULLSTR);
void SetCellText(short nsheet,int row, int col, _variant_t content);
void SetCellText(short nSheet,CString strCell, _variant_t Content);
void InsertPicsFromFile(LPCSTR path, short nsheet, double left, double top);
void InsertSheetsAfter(short nsheet, int num);
void SetColumnWidth(int nColF, int nColT, double dWidth);
void SaveQuit(CString strPath);
void ReleaseAllInterfaces();
void SetCellColor(short nSheet, CString Range, COLORREF rgb);
void SetCellColor(short nSheet, int row, int col, COLORREF rgb);
private:
int m_nTotalSheets;
int m_nCurSheet;
public:
_ApplicationPtr pApplication;
_WorkbookPtr pThisWorkbook;
_WorksheetPtr pThisWorksheet;
RangePtr pThisRange;
_variant_t vt ;
Excel::XlFileFormat vFileFormat ;
Excel::XlSaveAsAccessMode vSaveAsAccessMode ;
Excel::XlSaveConflictResolution vSaveConflictResolution ;
public:
SheetsPtr pThisSheets;
};
//cpp
/*EclOp.cpp*/
#include "stdafx.h"
#include "ExcelOprator.h"
CEclOp::CEclOp(void)
{
}
CEclOp::~CEclOp(void)
{
pThisRange.Release();
pThisRange.Release();
pThisWorksheet.Release();
pThisSheets.Release();
pThisWorkbook.Release();
pThisWorkbook.Release();
pApplication.Release();
::CoUninitialize();
}
void CEclOp::ReleaseAllInterfaces()
{
if (pThisRange != NULL)
pThisRange.Release();
if (pThisWorksheet != NULL)
pThisWorksheet.Release();
if (pThisSheets != NULL)
pThisSheets.Release();
if (pThisWorkbook != NULL)
pThisWorkbook.Release();
if (pApplication != NULL)
pApplication.Release();
::CoUninitialize();
}
BOOL CEclOp::Initialization(CString strPath)
{
if(FAILED(::CoInitialize(NULL)))
{
AfxMessageBox(TEXT("Initializing Excel Failed!"));
return FALSE;
}
pApplication = NULL;
pThisWorkbook = NULL;
pThisWorksheet = NULL;
pThisSheets = NULL;
pThisRange = NULL;
if (pApplication.CreateInstance(TEXT("Excel.Application")) != S_OK)
return FALSE;
//pApplication->PutVisible (0,VARIANT_TRUE);
pThisWorkbook = pApplication->GetWorkbooks()->Add((_variant_t)strPath) ;
pThisSheets = pThisWorkbook->GetWorksheets() ;
return TRUE;
}
void CEclOp::SetColumnWidth |