List Control中的内容导入到 .txt文件(可用记事本打开)
2011-08-17 22:14
281 查看
//按下导出按钮后的处理函数
void CFileDlg::OnButtonExport()
{
//从保存对话框中输入要保存到的文件和路径
CString strFileName;
CFileDialog m_ldFile(FALSE);
m_ldFile.m_ofn.lpstrFilter = "*.TXT ";
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 = 3; //List中的栏数
int iCount = m_List.GetItemCount();
for (int iItem = 0; iItem < iCount; iItem++)
for (int iCol = 0; iCol < iColSum; iCol++)
{
CString strTemp = m_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()));
"open ",
pszFileName,
NULL,
}
//是否立即查看该文件
if (MessageBox( "已保存,要查看吗 ", "完成 ", MB_YESNO) == IDYES)
{
ShellExecute(NULL,
NULL,
SW_SHOWNORMAL);
}
//关闭文件
myFile.Close();
}
void CFileDlg::OnButtonExport()
{
//从保存对话框中输入要保存到的文件和路径
CString strFileName;
CFileDialog m_ldFile(FALSE);
m_ldFile.m_ofn.lpstrFilter = "*.TXT ";
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 = 3; //List中的栏数
int iCount = m_List.GetItemCount();
for (int iItem = 0; iItem < iCount; iItem++)
for (int iCol = 0; iCol < iColSum; iCol++)
{
CString strTemp = m_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()));
"open ",
pszFileName,
NULL,
}
//是否立即查看该文件
if (MessageBox( "已保存,要查看吗 ", "完成 ", MB_YESNO) == IDYES)
{
ShellExecute(NULL,
NULL,
SW_SHOWNORMAL);
}
//关闭文件
myFile.Close();
}
相关文章推荐
- MapReduce编程实现txt文件中的内容导入HBase
- c# 我用文件流写文件 用/n或/r写到txt中 用记事本打开却是个小黑块 要输入回车符怎么输入啊
- MapReduce编程实现txt文件中的内容导入HBase
- 生成了一个txt文件,如何用记事本和EXCEL 打开它给用户看?
- ubuntu解决打开windows记事本.txt文件乱码的方法
- Python打开文件,将list、numpy数组内容写入txt文件中的方法
- ubuntu解决打开windows记事本txt文件乱码的问题
- 用记事本打开TXT文本文件
- Python打开文件,将list、numpy数组内容写入txt文件中
- Sqlldr导入txt文件内容到数据库中
- Ubuntu解决打开windows记事本.txt文件乱码的方法
- 数据导入,可以将txt文本文件或excel的内容导入到数据库
- 将txt文件内容导入mysql中,出现invalid utf8 character string错误的解决
- MFC 程序中调用记事本 NotePad 打开 txt 文件
- Windows7下TXT类型文件的右键菜单打开方式出现两个记事本的解决方案
- SSIS【Foreach 循环容器_Foreach 文件枚举器】(导入路径下的所有txt文件的内容) (转)
- 使用Unicode字符集时用CFile把中文写入txt文件再用记事本打开出现乱码的问题
- SQLServer将文件下所有的txt内容导入到数据库表
- windows server 2008下双击txt文件用记事本打开自动打印的问题解决
- 使用Unicode字符集时用CFile把中文写入txt文件再用记事本打开出现乱码的问题