Spread 8.0 Documentation
Example
Support Options

Glossary Item Box

Example


The following example exports the selected cells to a text file, using commas as the column delimiters, and carriage returns/line feeds as the row delimiters. The export occurs as soon as the user completes the selection.

To access the file used in this sample, change the path in the code to the path for your product installation's \SAMPLES\FILES directory.

C++

void CExportRangeToTextFileDlg::OnShowWindow(BOOL bShow, UINT nStatus)
{
    CDialog::OnShowWindow(bShow, nStatus);

    BOOL ret;
    CFont pFont;
    LOGFONT lf;
    // clear out structure
    memset(&lf, 0, sizeof(LOGFONT));
    // request a 12-pixel-height font
    lf.lfHeight = 24;
    lf.lfWeight = 800;
    // request a bold font
    strcpy(lf.lfFaceName, "Arial");
    // request a face name "Arial"
    pFont.CreateFontIndirect(&lf);
    // create the font
    m_Label.SetFont( &pFont, TRUE );
    m_Label.SetBackgroundColor(FALSE, RGB(214,211,206));
    m_Label.SetWindowText("Select cells to export to text file.");

    ret = m_Spread.LoadFromFile("address.ss7");

// Done with the font. Delete the font obj
    pFont.DeleteObject();
}

void CExportRangeToTextFileDlg::OnBlockSelectedSpread1(long BlockCol, long BlockRow, long BlockCol2, long BlockRow2)
{
// Export selecte
    BOOL ret;

    ret = m_Spread.ExportRangeToTextFile(BlockCol, BlockRow, BlockCol2, BlockRow2, "seltest.txt", "", ",", "\r\n", ExportRangeToTextFileCreateNewFile, "seltest.log")

// Let user know export is complete
    if( ret )
        AfxMessageBox("Export complete.");
    else
        AfxMessageBox("Export failed.");
}

Visual Basic

Private Sub Form_Load()
    ' Load sheet with data
    Dim ret As Boolean
    ret = fpSpread1.LoadFromFile("C:\Samples\Files\address.ss7")
    Label1.Caption = "Select cells to export to text file."
End Sub

Private Sub fpSpread1_BlockSelected(ByVal BlockCol As Long, ByVal BlockRow As Long, ByVal BlockCol2 As Long, ByVal BlockRow2 As Long)
    ' Export selected cells to text file
    Dim ret As Boolean
    ret = fpSpread1.ExportRangeToTextFile(BlockCol, BlockRow, BlockCol2, BlockRow2, "C:\Samples\seltest.txt", "", ",", vbCrLf, ExportRangeToTextFileCreateNewFile, "C:\Samples\seltest.log")
    ' Let user know export is complete
    If ret = True Then
        MsgBox "Export complete."
    Else
        MsgBox "Export failed."
    End If
End Sub

© 2002-2014 ComponentOne, a division of GrapeCity. All Rights Reserved.