使用 Spread Studio 表格控件你能夠複製範圍單元格而且填充到其餘單元格中,複製數據和單元格格式。例如:若是目前有 2*2 個單元格,你能夠在任意方向實現任意次數填充單元格到表單中。 html
咱們經過 FillRange 方法來實現此功能: post
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); }
效果圖:
使用控件地址: 點擊查看