void Csmyc::OnClickedButtonBc()
{
// TODO: 在此添加控件通知处理程序代码
WORD sYear, sMonth, sDay, sHour, sMinute, sSecond;
SYSTEMTIME CurTime;/////定义SYSTEMTIME类的对象
GetLocalTime(&CurTime);////获取本地时间
sYear = CurTime.wYear;////获得年
sMonth=CurTime.wMonth;//获得月
sDay = CurTime.wDay;
sHour = CurTime.wHour;
sMinute = CurTime.wMinute;
sSecond=CurTime.wSecond;
CString sFileName;
sFileName.Format(_T("%d年%d月%d日%d点%d分%d秒.xls"),
sYear, sMonth, sDay, sHour, sMinute, sSecond);
CFileDialog dlg(FALSE, ".xls", sFileName,OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY,"(*.xls)|*.xls||", this);
dlg.m_ofn.lpstrTitle = _T("保存文件");
if (dlg.DoModal() == IDOK)
{
// 实现存盘
CString buff0[1024], buff1[1024];
CString fileName = dlg.GetPathName();
CFile file(fileName,CFile::modeCreate | CFile::modeReadWrite | CFile::shareExclusive);
file.Write("失效模式\t 预测结果\n", 35);
int i = 0;
int j = 0;
j = m_ycjg_list.GetItemCount();
if (j > 0)
{
for (i = 0; i<j; i++)
{
buff0[i] = m_ycjg_list.GetItemText(i, 0);
buff1[i] = m_ycjg_list.GetItemText(i, 1);
CString msg;
msg.Format(_T("%s\t%s\n"), buff0[i], buff1[i]);
file.Write(msg, msg.GetLength());
}
}
file.Close();
}
return;
}
这是要输出的列表的数据:
这是输出到excel后的样子: