Load Excel Public DataSet loaddatafromexcel (string filePath) {try { String strconn; strconn = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" + FilePath + "; Extended properties= ' Excel 8.0; Hdr=false;imex=1 ' "; strconn = string. Format ("Provider=microsoft.ace.oledb.12.0;data source={0}; Extended properties= ' Excel 8.0; hdr=yes;imex=1; ' ", FilePath); OleDbConnection oleconn = new OleDbConnection (strconn); Oleconn.open (); String sql = "SELECT * FROM [sheet1$]";//change sheet name, such as Sheet2, etc. oledbdataadapter oledaexcel = new OLE DB DataAdapter (SQL, oleconn); DataSet oledsexcle = new DataSet (); Oledaexcel.fill (oledsexcle, "Sheet1"); Oleconn.close (); return oledsexcle; } catch (Exception err) {return null; } } <summary>//DataTable directly export Excel, this method will open the DataTable data in Excel, and then manually to save to the exact location///</summary> ; <param name= "DT" > to export Excel datatable</param>///<returns></returns> public Boo L Doexport (System.Data.DataTable dt) {Microsoft.Office.Interop.Excel.Application app = new Applicatio NClass (); if (app = = null) {throw new Exception ("Excel cannot Start"); } app. Visible = true; Workbooks WBS = App. Workbooks; Workbook wb = WBS. ADD (Missing.Value); Worksheet ws = (Worksheet) WB. WORKSHEETS[1]; int cnt = dt. Rows.Count; int columncnt = dt. Columns.count; Get Data ******************** object[,] objdata = new object[cnt + 1, columncnt]; Create cache data//Get column header for (int i = 0; i < columncnt; i++) {objdata[0, I] = dt. Columns[i]. ColumnName; }//Get specific data for (int i = 0; i < cnt; i++) {System.Data.DataRow dr = dt. Rows[i]; for (int j = 0; J < columncnt; J + +) {Objdata[i + 1, j] = Dr[j]; }}//********************* Write excel****************** Range r = Ws.get_range (app. Cells[1, 1], app. cells[cnt + 1, columncnt]); R.numberformat = "@"; R = R.get_resize (cnt+1, columncnt); R.value2 = Objdata; R.entirecolumn.autofit (); App = null; return true; }