DataGridView 컨트롤에 엑셀파일을 불러와서 바인딩하는 예제이다.
String name = "Sheet1"; //Name of your Sheet in the work book String constr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + "textfile.xlsx"+ ";Extended Properties='Excel 12.0 XML;HDR=YES;';"; OleDbConnection Connection = new OleDbConnection(constr); OleDbCommand OleConnection = new OleDbCommand("SELECT * FROM [" + name + "$]", Connection); Connection.Open(); OleDbDataAdapter sda = new OleDbDataAdapter(OleConnection); DataTable data = new DataTable(); sda.Fill(data); dataGridView1.DataSource = data;
<예제파일>