DataGrid1 = new DataGrid ( ) ;
button1 = new Button ( ) ;
SuspendLayout ( ) ;
DataGrid1.Name = "DataGrid1";
DataGrid1.Size = new System.Drawing.Size ( 400 , 200 ) ;
button1.Location = new System.Drawing.Point ( 124 , 240 ) ;
button1.Name = "button1" ;
button1.TabIndex = 1 ;
button1.Text = "读取数据" ;
button1.Size = new System.Drawing.Size (84 , 24 ) ;
button1.Click += new System.EventHandler ( this.button1_Click ) ;
this.AutoScaleBaseSize = new System.Drawing.Size ( 6 , 14 ) ;
this.ClientSize = new System.Drawing.Size ( 400 , 280 ) ;
this.Controls.Add ( button1 ) ;
this.Controls.Add ( DataGrid1 ) ;
this.Name = "Form1" ;
this.Text = "读取 Excle 表格中的数据,并用 DataGrid 显示出来!" ;
this.ResumeLayout ( false ) ;
}
private void button1_Click ( object sender , System.EventArgs e )
{
DataGrid1.DataMember= "[Sheet1$]" ;
DataGrid1.DataSource = myDataSet ;
}
static void Main ( )
{
Application.Run ( new Form1 ( ) ) ;
}
}
(4).总结
以上只是读取了 Excel 表格中"Sheet1"中的数据,对于其他"Sheet"中的内容,可以参照
读取"Sheet1"中的程序,只作一点修改就可以了,譬如要读取 "Sheet2"中的内容,只需要
把"Read.cs"程序中的"Sheet1$"改成"Sheet2$"就可以了。
评论3
最新资源