zoukankan      html  css  js  c++  java
  • VC++.net中导出list列表中的数据到TXT文档中

    导出的方法,先设置一个按钮,双击按钮,再按钮时件中添加如下代码

    注意项目属性的字符集要设置“未设置”

    CString strFileName;
    CFileDialog m_ldFile(FALSE);

    m_ldFile.m_ofn.lpstrFilter = "*.TXT";//这里注意注意:项目属性-配置属性-常规中的字符集要设置“未设置”(以前是unicode)
    m_ldFile.m_ofn.lpstrDefExt = "TXT";

    if (m_ldFile.DoModal() == IDOK)
    {
    strFileName = m_ldFile.GetPathName(); //设置保存路径
    }

    //创建文件
    char* pszFileName = strFileName.GetBuffer(strFileName.GetLength());
    CStdioFile myFile;
    CFileException fileException;

    if ( !myFile.Open( pszFileName, CFile::modeCreate |
    CFile::modeWrite ), &fileException )
    {
    TRACE( "Can't open file %s, error = %u\n",
    pszFileName, fileException.m_cause );
    }

    //文件中写入内容
    int iColSum = 4; //List中的栏数
    int iCount = List.GetItemCount();//这里的LIST是定义的list列表的变量

    for (int iItem = 0; iItem < iCount; iItem++)
    for (int iCol = 0; iCol < iColSum; iCol++)
    {
    CString strTemp = List.GetItemText( iItem, iCol);

    if (iCol ==0)
    lstrcat(strTemp.GetBuffer(strTemp.GetLength()), "\t");
    else
    lstrcat(strTemp.GetBuffer(strTemp.GetLength()), "\n");

    myFile.WriteString(strTemp.GetBuffer(strTemp.GetLength()));

    }


    if (MessageBox("已保存,要查看吗", "完成", MB_YESNO) == IDYES)
    {
    ShellExecute(NULL,
    "open",
    pszFileName,
    NULL,
    NULL,
    SW_SHOWNORMAL);
    }

    //关闭文件
    myFile.Close();

  • 相关阅读:
    mongoDB 索引
    mongoDB _id:ObjectId("xxxx")详解
    mongoDB: cursor not found on server
    mongoDB group命令详解
    Python 中,matplotlib绘图无法显示中文的问题
    python常用
    deepin下安装python的Tkinter库
    wireshark抓包常见提示含义解析
    TimeUnit
    Java回调机制解析
  • 原文地址:https://www.cnblogs.com/yanmingup/p/VCnet.html
Copyright © 2011-2022 走看看