컴퓨터/언어,프로그래밍

[스크랩] Excel 데이터를 C#으로 읽을 때

스노우볼^^ 2012. 9. 28. 13:32

         public void Read()

16     {
17         try
18         {
19             string ExcelFile = "test.xls";
20             string ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;"+
21                 "Data Source=c:\\myoun\\test.xls;"+"Extended Properties=Excel 8.0;";
22
23             OleDbConnection conn = new OleDbConnection(ConnectionString);
24             OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM Items", conn);
25
26             conn.Open();
27             MyDataSet = new DataSet("MyDataSet");
28             da.FillSchema(ds, SchemaType.Source, ExcelFile);
29             da.Fill(ds, ExcelFile);
30
31             //make changes to dataset
32             conn.Close();
33
34         }
35         catch(Exception e)
36         {
37             Console.WriteLine(e);
38         }
39     }

 

출처 : http://blog.naver.com/lovemingai/120056857053