With ASP.net do a simple game management background, involving the upload of Excel import data function, in the local development to achieve all good, can have uploaded the server on the tragedy, there is a good solution, we can refer to the following
Some time ago with ASP.net do a simple game management background, which involves uploading Excel import data function, originally in the local development is good, can have uploaded the server on the tragedy. Server is Aliyun Windows Server 2008 R2 (X64), after troubleshooting the server does not install Office this thing, there will be no OLE DB driver, do not want to install Office, especially Office 2010, looking at the size of the headache, how to do?
Baidu Google found that in fact, as long as the installation of Microsoft Access 2010 Database Engine Redistributable Package to implement the Microsoft Office System file and non-Microsoft Office applications transfer data between, support the existing Microsoft Office files (such as Microsoft Office Access *.mdb and *.accdb) files and Microsoft Office Excel (*.xls, *.xlsx, and *.XLSB) files) to transfer data between other data sources, such as Microsoft SQL Server. also supports establishing connections to existing text files. In addition, ODBC and OLE DB drivers are installed for application developers to use when developing applications that are connected to Office file formats. The installation package download address: http://www.microsoft.com/zh-cn/download/details.aspx?id=13255.
After the package is loaded, a piece of code is done.: code is as follows:///<summary> ///connect Excel to read Excel data and return DataSet data collection ///</summary > ///<param name= "filepath" >excel server path </param> ///<param name= "tablename" > Excel table name </param> ///<returns></returns> public static System.Data.DataSet Excelsqlconnection (string filepath, string tablename) { //string Strcon = "provider= Microsoft.jet.oledb.4.0;data source= "+ filepath +"; Extended properties= ' Excel 8.0; Hdr=yes;imex=1 ' "; string strcon =" Provider=microsoft.ace.oledb.12.0;data source= "+ filepath +"; Extended properties= ' Excel 12.0; Hdr=yes;imex=1 ' "; oledbconnection excelconn = new OleDbConnection (Strcon); try -{ String strCom = String. Format ("SELECT * from [sheet1$]"); Excelconn.open (); OleDbDataAdapter mycommand = new OleDbDataAdapter ( strcom, Excelconn); DataSet ds = new DataSet (); Mycommand.fill (ds, "[" + tablename + "$]"); &NBSp Excelconn.close (); return ds; } catch { excelconn.close (); return null; } }