Skip to main content

Posts

Showing posts with the label Data from Excel Sheet to Display In C#.Net Datagrid View

Data from Excel Sheet to Display In C#.Net Datagrid View

select data from an excel sheet and display it in a datagridview public void ImportExcel2007(string path) { FileInfo filePath = new FileInfo(path); DataTable workSheetsTable = new DataTable(); DataTable columnsTable = new DataTable(); string connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties='Excel 12.0;IMEX=1; HDR=YES'"; OleDbConnection excelConnection = new OleDbConnection(connString); excelConnection.Open(); //This bit assumes the first worksheet is the one to import, //change this as required. workSheetsTable = excelConnection.GetOleDbSchemaTable(OleDbSchemaGui d.Tables, null); string tableName = workSheetsTable.Rows[0]["TABLE_NAME"].To String(); //This section uses the tableName declared above to get a //list of columns for that worksheet only. columnsTable = excelConnection.GetOleDbSchemaTable(OleDbSchemaGu...