If you have any questions, add the QQ group.14670545Discussion
After exporting the Excel file on the Asp.net website, import the file to the database. An error occurred while reading the Excel file.
Error: The External table is not in the expected format.
An error occurred while opening the link in conn. open.
After carefully reading the link string, check whether an error occurs. If the Excel version is incorrect, the exce connection string version is office2003. If it is changed to excel2007, the data is imported normally.
The summary rules are as follows:
Using system. data. oledb; using system. data; Public void readexcelfiless (string excelpath) {// string strconn = "provider = Microsoft. jet. oledb.4.0; "+" Data Source = "+ excelpathexcelname. replace (@ "\", "\") + "; extended properties = 'excel 8.0; HDR = yes; IMEX = 1'"; // This connection can only operate on the top of excel2007(.xls) file string strconn = "provider = Microsoft. ace. oledb.12.0; "+" Data Source = "+ server. mappath ("excelfiles/mydata2007.x LSX ") +"; extended properties = 'excel 12.0; HDR = yes; IMEX = 1' "; // This connection can operate the. xlsand. XLSX files (supports the connection strings of excel2003 and excel2007) // note: "HDR = yes;" indicates that the first row of an Excel file is a column name rather than data. "HDR = no;" is the opposite of the previous one. // "IMEX = 1" if the data types in the column are inconsistent, use "IMEX = 1" to avoid data type conflicts. Oledbconnection conn = new oledbconnection (strconn); oledbdataadapter ADP = new oledbdataadapter ("select * from [sheet1 $]", Conn); dataset DS = new dataset (); ADP. fill (DS, "book1"); this. gridview1.datasource = Ds. tables ["book1"]. defaultview; this. gridview1.databind ();}
Of course, this processing method is always not safe, and the group number is constructed using office, Excel. dll.
Http://www.codeproject.com/Articles/8500/Reading-and-Writing-Excel-using-OLEDB