本帖最后由 dexteryao 于 2016-3-22 14:15 编辑
您好,很抱歉回复晚了,你的需求是可以实现的。
重点代码
- FpSpread1.Sheets[0].AutoGenerateColumns = false;
- FpSpread1.Sheets[0].Columns[0].DataField = "FirstName";
- FpSpread1.Sheets[0].Columns[4].DataField = "LastName";
复制代码
完整示例
- System.Data.DataSet ds = new System.Data.DataSet();
- DataTable name;
- DataTable city;
- name = ds.Tables.Add("Customers");
- name.Columns.AddRange(new DataColumn[] { new DataColumn("LastName", Type.GetType("System.String")), new DataColumn("FirstName", Type.GetType("System.String")), new DataColumn("ID", Type.GetType("System.Int32")) });
- name.Rows.Add(new object[] { "Fielding", "William", 0 });
- name.Rows.Add(new object[] { "Williams", "Arthur", 1 });
- name.Rows.Add(new object[] { "Zuchini", "Theodore", 2 });
- city = ds.Tables.Add("City/State");
- city.Columns.AddRange(new DataColumn[] { new DataColumn("City", Type.GetType("System.String")), new DataColumn("Owner", Type.GetType("System.Int32")), new DataColumn("State", Type.GetType("System.String")) });
- city.Rows.Add(new object[] { "Atlanta", 0, "Georgia" });
- city.Rows.Add(new object[] { "Boston", 1, "Mass." });
- city.Rows.Add(new object[] { "Tampa", 2, "Fla." });
- FpSpread1.Sheets[0].Columns.Count = 20;
- FpSpread1.Sheets[0].AutoGenerateColumns = false;
- FpSpread1.Sheets[0].Columns[0].DataField = "FirstName";
- FpSpread1.Sheets[0].Columns[4].DataField = "LastName";
- FpSpread1.Sheets[0].DataSource = ds;
复制代码
|