Server reads Excel does not install Office how to implement

Source: Internet
Author: User
Tags microsoft sql server ole table name

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; }  }   

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.