两种方案可供选择,代码如下:
- DataTable dt = new DataTable();
- dt.Columns.Add("Col1");
- dt.Columns.Add("Col2");
- dt.Columns.Add("Col3");
- dt.Rows.Add(1, 2, 3);
- dt.Rows.Add(2, 2, 3);
- dt.Rows.Add(3, 2, 3);
-
- //// 方法一
- //fpSpread1.ActiveSheet.DataSource = dt;
- //fpSpread1.ActiveSheet.ColumnCount += 1;
- //fpSpread1.ActiveSheet.MoveColumn(fpSpread1.ActiveSheet.ColumnCount - 1, 0, true);
- // 方法二
- fpSpread1.ActiveSheet.ColumnCount = 4;
- fpSpread1.ActiveSheet.AutoGenerateColumns = false;
- fpSpread1.ActiveSheet.Columns[1].DataField = "Col1";
- fpSpread1.ActiveSheet.Columns[2].DataField = "Col2";
- fpSpread1.ActiveSheet.Columns[3].DataField = "Col3";
- fpSpread1.ActiveSheet.DataSource = dt;
复制代码 |