把Excel的資料匯入至DataSet,再轉成ArrayList
1. 匯入
DataSet ds = new DataSet();
string sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + excelPathName + ";Extended Properties='Excel 8.0;HDR=YES;IMEX = 1';";
OleDbConnection OleDbCOnn = new OleDbConnection(sConnectionString);
OleDbDataAdapter OleDbAda = new OleDbDataAdapter(("select *from [Seet1$]"), OleDbCOnn);
try
{
OleDbCOnn.Open();
OleDbAda.Fill(ds);
}
catch (Exception e)
{
MessageBox.Show(e.Message.ToString());
//return true;
}
OleDbCOnn.Close();
OleDbAda.Dispose();
OleDbCOnn.Dispose();
2.將DataSet轉成ArrayList
foreach (DataRow dr in ds.Tables[0].Rows)
{
ArrayList s = new ArrayList();
foreach (DataColumn dc in ds.Tables[0].Columns)
{
s.Add(dr[dc.ColumnName]);
}
arrayDs.Add(s);
}
沒有留言:
張貼留言