Spread Windows Forms 15.0
Spread Windows Forms 15.0 Product Documentation / Developer's Guide / Cells / Managing Data on a Sheet / Repeatedly Filling a Range of Cells with Copied Cells
In This Topic
    Repeatedly Filling a Range of Cells with Copied Cells
    In This Topic

    You can copy a range of cells and fill another range with those cells, copying the data and the cell type with the FillRange method. For example, if you have a 2x2 range, you can repeat (fill) down the next five groups of 2x2 vertically.

    The parameters for the FillRange method are:

    Ranges of Cells Filled

    Using Code

    1. Add data to the cells.
    2. Set the FillRange method.

    Example

    For example, using this code, you would accomplish the results shown in the preceding figure.

    C#
    Copy Code
    // Define the text to repeat.
    fpSpread1.ActiveSheet.Cells[0, 0].Text = "A1-text";
    fpSpread1.ActiveSheet.Cells[0, 1].Text = "A2-text";
    fpSpread1.ActiveSheet.Cells[1, 0].Text = "B1-text";
    fpSpread1.ActiveSheet.Cells[1, 1].Text = "B2-text";
    
    fpSpread1.ActiveSheet.Cells[0, 0].BackColor = Color.Cyan;
    fpSpread1.ActiveSheet.Cells[0, 0].ForeColor = Color.DarkBlue;
    fpSpread1.ActiveSheet.Cells[0, 1].BackColor = Color.Coral;
    fpSpread1.ActiveSheet.Cells[0, 1].ForeColor = Color.DarkRed;
    
    // Fill 3 more columns to the right with the two columns' contents
    fpSpread1.ActiveSheet.FillRange(0, 1, 2, 1, 3, FarPoint.Win.Spread.FillDirection.Right);
    // Fill 4 more rows down with the contents of the square
    // of 2 rows and 2 columns
    fpSpread1.ActiveSheet.FillRange(0, 0, 2, 2, 4, FarPoint.Win.Spread.FillDirection.Down);
    
    VB
    Copy Code
    ' Define the text to repeat.
    fpSpread1.ActiveSheet.Cells(0, 0).Text = "A1-text"
    fpSpread1.ActiveSheet.Cells(0, 1).Text = "A2-text"
    fpSpread1.ActiveSheet.Cells(1, 0).Text = "B1-text"
    fpSpread1.ActiveSheet.Cells(1, 1).Text = "B2-text"
    
    fpSpread1.ActiveSheet.Cells(0, 0).BackColor = Color.Cyan
    fpSpread1.ActiveSheet.Cells(0, 0).ForeColor = Color.DarkBlue
    fpSpread1.ActiveSheet.Cells(0, 1).BackColor = Color.Coral
    fpSpread1.ActiveSheet.Cells(0, 1).ForeColor = Color.DarkRed
    
    ' Fill 3 more columns to the right with the two columns' contents
    fpSpread1.ActiveSheet.FillRange(0, 1, 2, 1, 3, FarPoint.Win.Spread.FillDirection.Right)
    ' Fill 4 more rows down with the contents of the square
    ' of 2 rows and 2 columns
    fpSpread1.ActiveSheet.FillRange(0, 0, 2, 2, 4, FarPoint.Win.Spread.FillDirection.Down)
    
    See Also