Spread Windows Forms 7.0 Product Documentation
Repeatedly Filling a Range of Cells with Copied Cells
See Also Support Options
Spread Windows Forms 7.0 Product Documentation > Developer's Guide > Managing Data on a Sheet > Placing and Retrieving Data > Repeatedly Filling a Range of Cells with Copied Cells

Glossary Item Box

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

Use the FillRange method. The parameters for this method are:

Ranges of Cells Filled

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

Example

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, 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, 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, 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, FillDirection.Down)

See Also

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