Objective Grid: Writing a grid to a text file

Article ID: 495
Last updated: 25 Apr, 2018
Article ID: 495
Last updated: 25 Apr, 2018
Revision: 3
Views: 1559
Posted: 12 Jan, 2001
by Meltreger B.
Updated: 25 Apr, 2018
by Meltreger B.

Problem

 


How can I write the grid to a text file in tab-delimited format?

 

 


Cause

 


 

 


Action

 


Objective Grid provides a method CopyTextToFile(). The following sample demonstrates how to write the whole grid with column headers to a text file.

void CGridSampleView::OnExportTextFile()
{
// pop-up file-open dlg to ask for location
CfileDialog dlgFile(
FALSE,
_T(".txt"),
NULL,
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
_T("Text Files (*.txt)|*.txt|All Files (*.*)|*.*||"));
if (dlgFile.DoModal() == IDCANCEL)
return;
CFile textFile;
if (!textFile.Open(dlgFile.GetFileName(), CFile::modeCreate | CFile::modeWrite))
{
TCHAR sz[255];
wsprintf(sz, "File %s could not be opened!", dlgFile.GetFileName());
AfxMessageBox(sz);

return;

}

CopyTextToFile( textFile, CGXRange(0, 1, GetRowCount(), GetColCount()) );
textFile.Close();

}

This article was:   Helpful | Not helpful
Report an issue
Article ID: 495
Last updated: 25 Apr, 2018
Revision: 3
Views: 1559
Posted: 12 Jan, 2001 by Meltreger B.
Updated: 25 Apr, 2018 by Meltreger B.

Others in this category