标签:
class ExcelDataBaseHelper { public static object OpenFile(string fileName, bool hasHeaders) { var fullFileName = fileName; string HDR = hasHeaders ? "Yes" : "No"; string connectionString; if (!File.Exists(fullFileName)) { System.Windows.Forms.MessageBox.Show("File not found"); return null; } if (fullFileName.Substring(fullFileName.LastIndexOf(‘.‘)).ToLower() == ".xlsx") connectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fullFileName + ";Extended Properties=\"Excel 12.0;HDR=" + HDR + ";IMEX=0\""); else connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fullFileName + ";Extended Properties=\"Excel 8.0;HDR=" + HDR + ";IMEX=0\""; var adapter = new OleDbDataAdapter("select * from [Sheet1$]", connectionString); var ds = new DataSet(); string tableName = "excelData"; adapter.Fill(ds, tableName); DataTable data = ds.Tables[tableName]; return data; } }
Devpress GridControl绑定DataTable数据
this.gridControl1.DataSource = ExcelDataBaseHelper.OpenFile(fp,true);
标签:
原文地址:http://www.cnblogs.com/TonyChan3/p/5222007.html