virtual BOOL CopyTextToFile(CFile& destFile, const CGXRangeList& selList);
BOOL CopyTextToFile(CFile& destFile, const CGXRange& range);
destFile
Specifies the CFile to which the results will be written.
selList
A reference to the range list which contains all the cell ranges which shall be written to the file.
range
Specifies a single range of cells which shall be written to the file.
Writes the text values of the specified range of cells in tab-delimited format to a CFile.
The second prototype of this method is simply a wrapper for calling CopyTextToFile with a single range instead of a range list.
The method will be called mainly for copying data in CF_TEXT format to the clipboard, but you may also use it for writing cell values to a tab-delimited text file.
CopyTextToFile determines the text which is written to the file by calling the CGXControl::GetControlText method for each cell. This makes sure that the text is written exactly as it is displayed in the cell (even if the style value is different from the displayed text for the cell, as for example in masked edit, RTF or comboboxes).
If you want to have a different column delimiter than the default tab ‘\t’, you might change the internal m_sExportTabDelim attribute in the CGXGridCore class.
Control-Factory Specific ->
This method has been implemented using the abstraction mechanism as discussed in the chapter "Reducing the size of your application" in the user's guide. A call to the ImplementTextDataExchange method from within the control factory class' InitializeGridComponents method will make the concrete implementation of this method available to your application.
If no concrete implementation is available this method returns FALSE. A warning will be displayed in the debug window.
END Control-Factory Specific
The following sample demonstrates how to write the whole grid with column headers and without row 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( );
}
CGXGridCore::Copy CGXGridCore::CopyRange CGXControl::GetControlText
Class Overview | Class Members