设为首页 加入收藏

TOP

一个vc的clistctrl的数据写到excel的方法(二)
2014-11-23 20:26:41 来源: 作者: 【 】 浏览:450
Tags:一个 clistctrl 数据 excel 方法
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
首页 上一页 1 2 3 4 下一页 尾页 2/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇出现"eh.h is only for C++!.. 下一篇CTaskDialog 的用法 例子 Visual ..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: