你可以尝试以下代码,主要是设置AutoGenerateColumns = false- private void Form1_Load(object sender, EventArgs e)
- {
- DataTable dt = new DataTable();
- dt.Columns.Add("col1");
- dt.Columns.Add("col2");
- dt.Columns.Add("col3");
- dt.Columns.Add("col4");
- dt.Rows.Add("1", "11", "111", "1111");
- dt.Rows.Add("2", "22", "222", "2222");
- dt.Rows.Add("3", "33", "333", "3333");
- dt.Rows.Add("4", "44", "444", "4444");
- fpSpread1.ActiveSheet.Columns[0].DataField = "col1";
- fpSpread1.ActiveSheet.Columns[1].DataField = "col2";
- fpSpread1.ActiveSheet.AutoGenerateColumns = false;
- fpSpread1.ActiveSheet.DataSource = dt;
- }
复制代码 |