MFC将数据写入excel

简介: MFC将数据写入excel
// 按键触发
// 导出报表
void CReportDlg::OnBnClickedButtonCheckOutExcel()
{
  CFileDialog dlg(false, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T("Excel Files(*.xls)|*.xls|All Files(*.*)|*.*|"), AfxGetMainWnd());
  CString strPath;
  if (dlg.DoModal() == IDOK)
  {
    strPath = dlg.GetPathName(); 
    if (strPath.Find(_T(".xls")) < 0) {
      strPath += _T(".xls");
    }
    ReportExcel(strPath);
  }
}


void CReportDlg::ReportExcel(LPCTSTR strPath)
{
  std::map<INT64, ReportClientInfo>::iterator it;
  TRY
  {
    CString cs;
    CStdioFile file(strPath, CFile::shareExclusive | CFile::modeWrite | CFile::modeCreate);
    setlocale(LC_CTYPE, ("chs")); //设置中文输出
    file.WriteString(_T("序号\t读卡器ID\t读卡器IP\t端口号\t连接状态\t连接上时刻\t断开连接时刻\n"));
    int row = 0;
    ReportClientInfo temp;
    for (it = m_reportMap.begin(); it != m_reportMap.end(); ++it)
    {
      temp = it->second;
      cs.Format(_T("%d\t`%s\t%s\t%s\t%s\t%s\t%s\n"),
        ++row,
        temp.ReaderID,
        temp.ReaderIP,
        temp.ReaderPort,
        temp.ConnectStutes,
        temp.ConnectTime,
        temp.DisConnectTime);
      file.WriteString(cs);
    }
    file.Close();
    AfxMessageBox(_T("导出成功"));
  }
  CATCH_ALL(e)
  {
    e->ReportError();
    return;
  }
  END_CATCH_ALL
}
相关文章
|
26天前
|
SQL 缓存 easyexcel
面试官问10W 行级别数据的 Excel 导入如何10秒处理
面试官问10W 行级别数据的 Excel 导入如何10秒处理
52 0
|
1月前
|
安全 Java 数据库连接
jdbc解析excel文件,批量插入数据至库中
jdbc解析excel文件,批量插入数据至库中
21 0
|
1月前
|
Java API Apache
使用AOP+反射实现Excel数据的读取
使用AOP+反射实现Excel数据的读取
|
1月前
|
SQL 数据可视化 数据处理
使用SQL和Python处理Excel文件数据
使用SQL和Python处理Excel文件数据
54 0
|
1月前
|
安全 Java 数据库连接
jdbc实现批量给多个表中更新数据(解析Excel表数据插入到数据库中)
jdbc实现批量给多个表中更新数据(解析Excel表数据插入到数据库中)
154 0
|
1月前
|
存储 数据处理 Python
使用Python批量合并Excel文件的所有Sheet数据
使用Python批量合并Excel文件的所有Sheet数据
33 0
|
1月前
|
存储 数据处理 Python
使用openpyxl库从Excel文件中提取指定的数据并生成新的文件
使用openpyxl库从Excel文件中提取指定的数据并生成新的文件
29 0
|
1月前
|
存储 数据处理 数据格式
Python中导入Excel数据:全面解析与实践
Python中导入Excel数据:全面解析与实践
42 0
|
1月前
|
存储 数据采集 数据可视化
Python如何读取Excel中的数据?
Python如何读取Excel中的数据?
23 0
|
1月前
|
存储 关系型数据库 MySQL
Python导入Excel数据到MySQL数据库
Python导入Excel数据到MySQL数据库
93 0