MFC数据listcontroler导出到excel(支持图片、支持右键、源码)

时间:2024-03-30 09:36:37

效果展示

首先点击插入行,插入数据

MFC数据listcontroler导出到excel(支持图片、支持右键、源码)

导出到excel,点击打开图片

MFC数据listcontroler导出到excel(支持图片、支持右键、源码)

 

关键代码

void CBlogDlg::OnMenuout()
{
	// TODO: 在此添加命令处理程序代码
	CTime time=CTime::GetCurrentTime();
	CString strRptTime =time.Format("%Y%m%d_%H%M%S");

	CFileDialog dlg(FALSE, ".xls", strRptTime, OFN_OVERWRITEPROMPT|OFN_HIDEREADONLY,"(*.xls)|*.xls||", this);dlg.m_ofn.lpstrTitle = _T("导出文件");
	if (dlg.DoModal() == IDOK)
	{
		// 实现存盘
		CString buff0[1024],buff1[1024],buff2[1024],buff3[1024],buff4[1024];
		CString fileName = dlg.GetPathName();
		CFile file(fileName,CFile::modeCreate|CFile::modeReadWrite|CFile::shareExclusive);


		CFile file1;



		file.Write("操作\t表号\t读取类型\t图片\n",24);

		int i = 0;
		int j=0;
		j = m_ctllist.GetItemCount();
		if( j > 0 )
		{
			for(i=0;i<j;i++)
			{
				buff0[i] = m_ctllist.GetItemText( i, 0 );
				buff1[i] = m_ctllist.GetItemText( i, 1 );
				buff2[i] = m_ctllist.GetItemText( i, 2 );
				buff3[i] = "=HYPERLINK(\"c:\\Picture\\20180925_172837.jpg\",\"点击显示\")";

				//file1.Open("c:\\Picture\\20180925_172837.jpg",CFile::modeReadWrite);
				//ULONGLONG len = file1.GetLength();
				////char buf[1024]={0};
				//file1.Read(buff3,len);

				buff4[i] = m_ctllist.GetItemText( i, 4 );
				CString msg;
				msg.Format("%s\t%s\t%s\t%s\t%s\n",buff0[i],buff1[i],buff2[i],buff3[i],buff4[i]);
				file.Write(msg,msg.GetLength());

			}
		}
		file.Close();
	}
}

使用VS2008开发,其他软件可以参考代码

工程源码:

https://download.csdn.net/download/u011752195/10749957