MFC输出EXCEL文档的过程总结
由于目前的工作内容涉及到了几处需要输出EXCEL表格的内容,因此在网上也查找了些资料,在下面总结下,以方便使用;
1、当你输出的内容已经在输出的时候全部知道,并且输出格式已经固定,那么你就可以使用下面的方法输出,用if( (pfile = fopen(strFileName, "wb+")) != NULL)
打开EXCEL,然后在其中用fprintf写入,用\T到下一个单元格,用\n到下一行;适合输出内容固定,格式固定的内容。
[cpp]
</pre><pre name="code" class="cpp">void CRqEquipReqView::SaveDxcFileXLS(CString strFileName, BOOL bSaveAsAll)
{
FILE *pfile = NULL;
CString strGroupName;
CString strMain, strSlave;
CString strMainName, strMainCreateTime, strMainDirection, strMainCap, strMainStatus;
CString strMainSrc, strMainSrcAccess, strMainSrcConGroup;
CString strMainDst, strMainDstAccess, strMainDstConGroup;
CString strProName, strProCreateTime, strProDirection, strProCap, strProStatus;
CString strProSrc, strProSrcAccess, strProSrcConGroup;
CString strProDst, strProDstAccess, strProDstConGroup;
strMain.LoadString(IDS_RQNLPCT_MAIN);
strSlave.LoadString(IDS_RQNLPCT_SLAVE);
if(m_pRqGroup)
{
strGroupName = m_pRqGroup->GetName();
}
int MainCount = m_lstDxc.GetItemCount();
int ProCount = m_lstProtDxc.GetItemCount();
//参数中带'b'的话是以二进制文件形式打开文件, 否则是以文本文件打开.
//以文本文件形式打开时, 值26就作为EOF了, 前者则不会.
//如果不是保存成文本形式的话, 切记加上'b'
//"a "模式在添加数据前并不清除EOF标志,添加数据后用MS-DOS的TYPE命令只能显示数据到原来EOF标志,而并不会显示后来添加的.
//"a+ "模式会清除EOF标志,添加数据后,用MS-DOS的TYPE命令能显示所有的数据."a+ "模式需要以CTRL+Z EOF标志结束的流输入.
if( (pfile = fopen(strFileName, "wb+")) != NULL)
{
fprintf(pfile, strGroupName + "-" + strMain + "\n");
CString strItem;
strItem.LoadString(IDS_RQSUBNET_DXCNAME);
fprintf(pfile, strItem + "\t");
strItem.LoadString(IDS_RQSUBNET_DXCCAP);
fprintf(pfile, strItem + "\t");
strItem.LoadString(IDS_RQSUBNET_DXCDIR);
fprintf(pfile, strItem + "\t");
strItem.LoadString(IDS_RQSUBNET_SRCCARD);
fprintf(pfile, strItem + "\t");
strItem.LoadString(IDS_RQSUBNET_SRCAP);
fprintf(pfile, strItem + "\t");
strItem.LoadString(IDS_RQSUBNET_SRCCONNECTGROUP);
fprintf(pfile, strItem + "\t");
strItem.LoadString(IDS_RQSUBNET_DSTCARD);
fprintf(pfile, strItem + "\t");
strItem.LoadString(IDS_RQSUBNET_DSTAP);
fprintf(pfile, strItem + "\t");
strItem.LoadString(IDS_RQSUBNET_DSTCONNECTGROUP);
fprintf(pfile, strItem + "\t");
strItem.LoadString(IDS_STATUS);
fprintf(pfile, strItem + "\t");
strItem.LoadString(IDS_DXCCREATETIME);
fprintf(pfile, strItem + "\t\n");
CRqNeDxc rqNeDxc;
for(int mainDxc = 0; mainDxc < m_lstDxc.GetItemCount(); mainDxc++)
{
int iDxcID = m_lstDxc.GetItemData(mainDxc);
if (!m_bSingle)
{
if(iDxcID < m_vRqNeDxcBiDsp.size())
{
rqNeDxc = m_vRqNeDxcBiDsp[iDxcID];
}
else
{
rqNeDxc = m_vRqNeDxcUniDsp[iDxcID - m_vRqNeDxcBiDsp.size()];
}
}
else
{
rqNeDxc = m_vRqDxc[iDxcID];
}
if(!bSaveAsAll && !rqNeDxc.GetSelected())
{
continue;
}
strMainName = m_lstDxc.GetItemText(mainDxc, NAMECOL);
strMainCap = m_lstDxc.GetItemText(mainDxc, CAPCOL);
strMainDirection = m_lstDxc.GetItemText(mainDxc, DIRCOL);
strMainSrc = m_lstDxc.GetItemText(mainDxc, SRCCARDCOL);
strMainSrcAccess = m_lstDxc.GetItemText(mainDxc, SRCTU12COL);
&nbs
补充:软件开发 , Vc ,