How can I write the grid to a text file in tab-delimited format?
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();
}