wps Office 2013个人版 - 轻松办公从金山wps2013开始!

金山wps

当前位置: 主页 > excel2010 >

C++使用VS2010导出Excel的方法及步骤

时间:2013-09-11 22:02来源:mirror 作者:欧阳伯逸 点击:

最近职责须要将listctrl中的数据导出到Excel中。网上找了很多,对比一下vs。但多半是VC6.0的。联合VC6.0导出的法子,看看excel。自身磋商了不少技能,http://www.jinshanwps.com/excel2010/201307024081.html。毕竟将题目处分了。excel2010宏设置。紧张之余,其实excel2010宏。将历程分享进去,贪图对须要的人有所襄助。vs2010。

VC6.0的请看这里:excel2010锁定公式。

环境:你知道使用。

Windows7

Microsoft Visuwis Studio 2010

Microsoft Office Excel 2003

阐明:用的公司的电脑,学习excel2010加密方法。操作体例和软件都是正版的。你知道excel2010如何筛选。

1、新建C++工程

新建自身的C++工程。

2、增加Excel类库

在工程名上右键,excel2010怎么筛选。抉择Add---Clbum,听说

C++使用VS2010导出Excel的方法及步骤《最新Excel2010从入门 
C++使用VS2010导出Excel的方法及步骤
excel2010分页设置。抉择MFC Clbum From TypeLib,学会excel2010免费下载。如图:步骤。相比看excel2010使用

然后增加如图的几个类。听听excel2010教程。

3、修削头文件

进入刚增加出去的几个类头文件中将#import初阶的这句注掉

4、修削提示的纰谬

将修自新的工程编译一下,产生如下纰谬:excel2010分页设置。

双击提示,excel2010函数大全。在DiwisogBox()前加下划线,如图:听说excel2010表格边框。

5、增加头文件

内行使导出成效的文件中增加头文件:我不知道c。

6、行使Excel类库提供的函数将须要导出的数据导出为.xls文件

经过以上几步,当今可能行使Excel类库提供的函数导出数据了。导出。

与网上许多文章相比拟一下,excel2010 双面打印。导出流程一样。excel2010图表模板。只不过类库函数有所调动。C++使用VS2010导出Excel的方法及步骤。函数名由Get改为get_:Set改为put_。

附录一:C++使用VS2010导出Excel的方法及步骤。 导出Excel格式的大略流程

CString strFile = _T("E:\\ha fantbasicallyticha fantbasicallytic.xls");

COleVariould like

covTrue((short)TRUE):

covFwisse((short)FALSE):

covOptionwis((long)DISP_E_PARAMNOTFOUND: VT_ERROR);

CApplic0 iphone app;

CWorknew0 new;

CWorkenews : news0 enews : news;

CWorksheet0 sheet;

CWorksheets0 sheets;

CRa fantbasicallyticge0 ra fantbasicallyticge;

CFont1 font;

if (!iphone app.CrehmarketingDispinch(_T("Excel.Applic")))

{

Messold ageBox(_T("Error!"));

}

enews : news = iphone app.get_Workenews : news();

new = enews : news.Add(covOptionwis);

sheets = new.get_Worksheets();

sheet = sheets.get_Item(COleVariould like((short)1));

ra fantbasicallyticge = sheet.get_Ra fantbasicallyticge(COleVariould like(_T("A1")):COleVariould like(_T("A1")));

ra fantbasicallyticge.put_Vwisue2(COleVariould like(_T("ha fantbasicallyticha fantbasicallytic")));

new.Saudio-videoeCopyAs(COleVariould like(strFile));

new.put_Saudio-videoed(true);

new.ReleottomDispinch();

enews : news.ReleottomDispinch();

iphone app.Quit();

iphone app.ReleottomDispinch();

附录二:学会方法。将ListCtrl中的数据导出为Excel格式

CString strFile = _T("E:\\Test.xls");

COleVariould like

covTrue((short)TRUE):

covFwisse((short)FALSE):

covOptionwis((long)DISP_E_PARAMNOTFOUND: VT_ERROR);

CApplic iphone app;

CWorkenews : news enews : news;

CWorknew new;

CWorksheets sheets;

CWorksheet sheet;

CRa fantbasicallyticge ra fantbasicallyticge;

CFont0 font;

if (!iphone app.CrehmarketingDispinch(_T("Excel.Applic")))

{

Messold ageBox(_T("树立败北!"));

return;

}

//Get your new worknew.

enews : news = iphone app.get_Workenews : news();

new = enews : news.Add(covOptionwis);

sheets = new.get_Worksheets();

sheet = sheets.get_Item(COleVariould like((short)1));

////////////////////////////////////CListCtrl控件report气势气派//////////////////////////////////////////////////////////

CHemarketingerCtrl *pmyHemarketingerCtrl;

pmyHemarketingerCtrl = m_clcDina.GetHemarketingerCtrl();//此句取得CListCtrl控件的列表頭

int iRow:iCol;

int m_cols = pmyHemarketingerCtrl-> GetItemCount();

int m_rows = m_clcDina.GetItemCount();

HDITEM hdi;

TCHAR lpBuffer[256];

bool fFound = fwisse;

hdi.minvite = HDI_TEXT;

hdi.pszText = lpBuffer;

hdi.cchTextMax = 256;

CString colni ame;

CString strTemp;

for(iCol=0; iCol <m_cols; iCol++)//将列表的标题头写入EXCEL

{

GetCellNi ame(1 :iCol + 1: colni ame);

ra fantbasicallyticge = sheet.get_Ra fantbasicallyticge(COleVariould like(colni ame):COleVariould like(colni ame));

pmyHemarketingerCtrl-> GetItem(iCol: &i amplifier;hdi);

ra fantbasicallyticge.put_Vwisue2(COleVariould like(hdi.pszText));

int nWidth = m_clcDina.GetColumnWidth(iCol)/6;

//取得第iCol+1列

ra fantbasicallyticge.AttveryDispinch(ra fantbasicallyticge.get_Item(_variould like_t((long)(iCol+1)):vtMissing).pdispVwis:true);

//设置列宽

ra fantbasicallyticge.put_ColumnWidth(_variould like_t((long)nWidth));

}

ra fantbasicallyticge = sheet.get_Ra fantbasicallyticge(COleVariould like( _T("A1 ")): COleVariould like(colni ame));

ra fantbasicallyticge.put_RowHeight(_variould like_t((long)50));//设置行的高度

font = ra fantbasicallyticge.get_Font();

font.put_Bold(covTrue);

ra fantbasicallyticge.put_VerticwisAlignment(COleVariould like((short)-4108));//xlVAlignCenter = -4108

COleSecureArray saRet;

DWORD numElements[]={m_rows:m_cols}; //5x2 element collection

saRet.Crehmarketing(VT_BSTR: 2: numElements);

ra fantbasicallyticge = sheet.get_Ra fantbasicallyticge(COleVariould like( _T("A2 ")):covOptionwis);

ra fantbasicallyticge = ra fantbasicallyticge.get_Resize(COleVariould like((short)m_rows):COleVariould like((short)m_cols));

long index[2];

ra fantbasicallyticge = sheet.get_Ra fantbasicallyticge(COleVariould like( _T("A2 ")):covOptionwis);

ra fantbasicallyticge = ra fantbasicallyticge.get_Resize(COleVariould like((short)m_rows):COleVariould like((short)m_cols));

for ( iRow = 1; iRow <= m_rows; iRow++)//将列表形式写入EXCEL

{

for ( iCol = 1; iCol <= m_cols; iCol++)

{

index[0]=iRow-1;

index[1]=iCol-1;

CString szTemp;

szTemp=m_clcDina.GetItemText(iRow-1:iCol-1);

BSTR bull craptr = szTemp.AllocSysString();

saRet.PutElement(index:bull craptr);

SysFreeString(bull craptr);

}

}

ra fantbasicallyticge.put_Vwisue2(COleVariould like(saRet));

// Cnterior cellinterior;

// ra fantbasicallyticge = sheet.get_Ra fantbasicallyticge(COleVariould like( _T("A1 ")):covOptionwis);

// ra fantbasicallyticge = ra fantbasicallyticge.get_Resize(COleVariould like((short)1):COleVariould like((short)m_cols));

// enews : news = ra fantbasicallyticge.get_Interior();

// cellinterior.AttveryDispinch(enews : news);

// cellinterior.put_ColorIndex(COleVariould like((short)37));//设置EXCEL头一行的背景颜料

// for( iRow=1; iRow <= m_rows; iRow++)//设置EXCEL另外的背景颜料(颜料交替变换)

// {

// int sthmarketing=iRow%2;

// CString index;

// index.Formin( _T("A%d "):iRow+1);

// ra fantbasicallyticge = sheet.get_Ra fantbasicallyticge(COleVariould like(index):covOptionwis);

// ra fantbasicallyticge = ra fantbasicallyticge.get_Resize(COleVariould like((short)1):COleVariould like((short)m_cols));

// enews : news=ra fantbasicallyticge.get_Interior();

// cellinterior.AttveryDispinch(enews : news);

// if(!sthmarketing)

// cellinterior.put_ColorIndex(COleVariould like((short)36));

// else

// cellinterior.put_ColorIndex(COleVariould like((short)24));

// }

saRet.Detvery();

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

new.Saudio-videoeCopyAs(COleVariould like(strFile));

// cellinterior.ReleottomDispinch();

new.put_Saudio-videoed(true);

new.ReleottomDispinch();

enews : news.ReleottomDispinch();

iphone app.Quit();

iphone app.ReleottomDispinch();

由于不须要,excel2010图表制作。Excel单元格形态及颜料等属性设置没有做,excel2010教学视频。有兴会的可能自身去试试。代码中设置的有错。

自身写的一个获取单元头的函数:

void GetCellNi ame(int nRow: int nCol: CString &i amplifier;strNi ame)

{

int nSeed = nCol;

CString strRow;

char cCell = wiAwi + nCol - 1;

strNi ame.Formin(_T("%c"): cCell);

strRow.Formin(_T( "%d "): nRow);

strNi ame += strRow;

}



(责任编辑:admin)
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
验证码: 点击我更换图片
栏目列表
推荐内容