使用 Spread Studio 表格控件你可以复制范围单元格并且填充到其他单元格中,复制数据和单元格格式。例如:如果目前有 2*2 个单元格,你可以在任意方向实现任意次数填充单元格到表单中。
我们通过 FillRange 方法来实现此功能:
public void FillRange( int row, int column, int rowCount, int columnCount, int fillCount, FillDirection fillDirection )
参数
- row
- 开始复制单元格范围的行索引
- column
- 开始复制单元格范围的列索引
- rowCount
- 复制单元格范围的行数
- columnCount
- 复制单元格范围的行数
- fillCount
- 填充次数
- fillDirection
- 填充方向
测试代码:
private void Form1_Load(object sender, EventArgs e) { // 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; } private void 横向填充ToolStripMenuItem_Click(object sender, EventArgs e) { //向右填充 fpSpread1.ActiveSheet.FillRange(0, 1, 2, 1, 3, FillDirection.Right); } private void 向下填充ToolStripMenuItem_Click(object sender, EventArgs e) { //向下填充 fpSpread1.ActiveSheet.FillRange(0, 0, 2, 2, 4, FillDirection.Down); }
效果图:
Demo 下载:vs2010 && Spread Studio Windows Form .NET 7