我写了一段简单的代码,主要实现思路是
1、将国家的城市取出,并设置到Spread的列上
2、将所有需要填写的基本信息取出,并设置到Spread的行上
代码:- private void Form1_Load(object sender, EventArgs e)
- {
- // 创建该国家的城市信息
- DataTable dtCity = new DataTable();
- dtCity.Columns.Add("ID");
- dtCity.Columns.Add("City");
- for (int i = 0; i < 10; i++)
- {
- dtCity.Rows.Add(i, "城市:" + (i + 1).ToString());
- }
- fpSpread1.ActiveSheet.ColumnCount = dtCity.Rows.Count+1;
- fpSpread1.ActiveSheet.Columns[0].Label = "基本信息";
- fpSpread1.ActiveSheet.Columns[0].Width = 100;
- for (int i = 0; i < dtCity.Rows.Count; i++)
- {
- fpSpread1.ActiveSheet.Columns[i+1].Label = dtCity.Rows[i]["City"].ToString();
- }
- // 创建城市的基本信息
- DataTable dtInfo = new System.Data.DataTable();
- dtInfo.Columns.Add("ID");
- dtInfo.Columns.Add("Info");
- for (int i = 0; i < 5; i++)
- {
- dtInfo.Rows.Add(i, "基本信息:" + (i + 1).ToString());
- }
- fpSpread1.ActiveSheet.RowCount = dtInfo.Rows.Count;
- for (int i = 0; i < dtInfo.Rows.Count; i++)
- {
- fpSpread1.ActiveSheet.Cells[i, 0].Value = dtInfo.Rows[i]["Info"].ToString();
- }
- }
复制代码 |