string sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + path + ";" +
"Extended Properties=Excel 8.0;";
//建立EXCEL的連接
OleDbConnection objConn = new OleDbConnection(sConnectionString);
objConn.Open();
OleDbCommand objCmdSelect = new OleDbCommand("SELECT * FROM [Sheet5$]", objConn);
OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
objAdapter1.SelectCommand = objCmdSelect;
DataSet objDataset1 = new DataSet();
objAdapter1.Fill(objDataset1, "XLData");
System.Data.DataTable dtExcel = objDataset1.Tables[0];
objConn.Close();
xSt.Range[excel.Cells[rowIndex, num + 1], excel.Cells[rowIndex, num + 1]].HorizontalAlignment = XlVAlign.xlVAlignCenter;
xSt.SaveAs(xlsFile);