Spread 8.0 Documentation
Example
Support Options

Glossary Item Box

Example


The following example lets the user select cells, then click the Span button to create a span range for the selected cells. The user can also select a cell, then click the Remove Span button to remove a span range, if one exists.

C++

void CTestprojDlg::OnButton2()
{
    VARIANT col, row, col2, row2, anchorcol, anchorrow, colspan, rowspan;
    long Span, i, j;
    BOOL IsSpan = FALSE;
    // Get the selected cells
    m_Spread1.GetSelection(0, &col, &row, &col2, &row2);
    // Check to see if cells are already in span
    for (i = col.lVal; i<= col2.lVal; i++) {
        for (j = row.lVal; j<= row2.lVal; j++) {
            Span = m_Spread1.GetCellSpan(i, j, &anchorcol, &anchorrow, &colspan, &rowspan);
            // If in span, don't create new span, and notify user
            if (Span > 0) {
                i = col2.lVal;
                j = row2.lVal;
                MessageBox( "Cells are already part of span.");
                IsSpan = TRUE;
            }
        }
    }

    // If none of the cells are in a span, create a new span
    if (IsSpan == FALSE)
        IsSpan = m_Spread1.AddCellSpan(col.lVal, row.lVal, (col2.lVal - col.lVal + 1), (row2.lVal - row.lVal + 1));
}

void CTestprojDlg::OnButton3(){
    VARIANT col, row, col2, row2, anchorcol, anchorrow, colspan, rowspan;
    long Span, i, j;
    BOOL IsSpan = FALSE;
    // Get the selected cells
    m_Spread1.GetSelection(0, &col, &row, &col2, &row2);
    // Check to see if cells are already in span
    for (i = col.lVal; i <= col2.lVal; i++) {
        for (j = row.lVal; j <= row2.lVal; j++) {
            Span = m_Spread1.GetCellSpan(i, j, &anchorcol, &anchorrow, &colspan, &rowspan);
            // If cells are in span, remove span
            if (Span > 0) {
                m_Spread1.RemoveCellSpan(anchorcol.lVal, anchorrow.lVal);
                IsSpan = TRUE;
            }
        }
    }
    if (IsSpan == FALSE)
        MessageBox ("No spans to remove.");
}

Visual Basic

Private Sub Command1_Click()
    Dim col As Variant
    Dim row As Variant
    Dim col2 As Variant
    Dim row2 As Variant
    Dim Span As Integer
    Dim anchorcol As Variant
    Dim anchorrow As Variant
    Dim colspan As Variant
    Dim rowspan As Variant
    Dim i As Long
    Dim j As Long
    Dim IsSpan As Boolean

    ' Get the selected cells
    fpSpread1.GetSelection 0, col, row, col2, row2

    ' Check to see if cells are already in span
    For i = col To col2
        For j = row To row2
            Span = fpSpread1.GetCellSpan(i, j, anchorcol, anchorrow, colspan, rowspan)
            ' If in span, don't create new span, and notify user
            If Span Then
                i = col2
                j = row2
                MsgBox "Cells are already part of span."
                IsSpan = True
            End If
        Next j
    Next i

    ' If none of the cells are in a span, create a new span
    If IsSpan = False Then
        fpSpread1.AddCellSpan col, row, (col2 - col + 1), (row2 - row + 1)
    End If

End Sub

Private Sub Command2_Click()
    Dim col As Variant
    Dim row As Variant
    Dim col2 As Variant
    Dim row2 As Variant
    Dim Span As Integer
    Dim anchorcol As Variant
    Dim anchorrow As Variant
    Dim colspan As Variant
    Dim rowspan As Variant
    Dim i As Long
    Dim j As Long
    Dim IsSpan As Boolean

    ' Get the selected cells
    fpSpread1.GetSelection 0, col, row, col2, row2

    ' Check to see if cells are already in span
    For i = col To col2
        For j = row To row2
            Span = fpSpread1.GetCellSpan(i, j, anchorcol, anchorrow, colspan, rowspan)
            ' If cells are in span, remove span
            If Span Then
                fpSpread1.RemoveCellSpan anchorcol, anchorrow
                IsSpan = True
            End If
        Next j
    Next i

    If IsSpan = False Then
        MsgBox "No spans to remove."
    End If

End Sub

Copyright © GrapeCity, inc. All rights reserved.