After you export the Excel file in the ASP. NET Web site, import the file into the database. Error opening connection when reading Excel file.
Error: External table is not in expected format
FIX: Checked, the exported Excel is standard file is not HTML, yes, Excel file is normal.
Debug code, create Connection object OleDbConnection is also normal, but in Conn. Open () An error occurred while opening the link.
Look closely at the link string, check out the error, Excel version problem, EXCE connection string version is office2003, change to Excel2007 version is normal import.
The summary rules are as follows:
usingSystem.Data.OleDb;usingSystem.Data; Public voidreadexcelfiless () {//string strconn = "provider=microsoft.jet.oledb.4.0;" + "Data source=" + Server.MapPath ("Excelfiles/myexcelfile.xls ") + "; Extended properties= ' Excel 8.0; Hdr=yes; Imex=1 ' "; //This connection can only manipulate Excel2007 (. xls) files stringstrconn ="provider=microsoft.ace.oledb.12.0;"+"Data source="+ Server.MapPath ("excelfiles/mydata2007.xlsx") +"; Extended properties= ' Excel 12.0; Hdr=yes; Imex=1 '";//This connection can manipulate the. xls and. xlsx files (connection strings that support Excel2003 and Excel2007)//remark: "Hdr=yes;" Is that the first line of the Excel file is the column name instead of the data, "HDR=NO;" It's just the opposite of the front. //"Imex=1" if the data type in the column is inconsistent, the use of "imex=1" will avoid data type collisions. OleDbConnection Conn=NewOleDbConnection (strconn); OleDbDataAdapter ADP=NewOleDbDataAdapter ("Select * FROM [sheet1$]", conn); DataSet DS=NewDataSet (); Adp. Fill (DS,"Book1"); This. Gridview1.datasource = ds. tables["Book1"]. DefaultView; This. Gridview1.databind (); }
From: https://www.cnblogs.com/kingkongv/archive/2012/08/26/2657436.html
Import bulk Excel data into an Oracle database import Excel error: External table is not the expected format solution