Asp.Net (C #) - Reading an Excel worksheet

I have a requirement to make some imports from a worksheet with an Excel extension and browse various examples on the Internet, all of them seem to use the "Jet" driver, which is incompatible with 64Bit.

Now I am fully aware of workarounds (when changing how IIS works, etc.), however I would like to know if there is a replacement for the Jet driver so that I can read and generate excel sheets from Asp.Net, running on a 64-bit server without IIS changes.

+4
source share
3 answers

The last time I researched, there is no x64 driver. I use this to open xls files. It works on 64-bit blocks while you compile using x86.

DataSet myDataset = new DataSet(); string strConn = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filename + @";Extended Properties=""Excel 12.0 Xml;HDR=YES"""; OleDbConnection myData = new OleDbConnection(strConn); try { myData.Open(); } catch (OleDbException e) { try { strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + filename + ";" + "Extended Properties=Excel 8.0;HDR=YES;"; myData = new OleDbConnection(strConn); myData.Open(); } catch (Exception e2) { strConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filename + @";Extended Properties=""HTML Import;HDR=YES;IMEX=1"";"; myData = new OleDbConnection(strConn); myData.Open(); } } int i = 0; foreach (DataRow row in myData.GetSchema("tables").Rows) try { i++; string name = row[2].ToString().Replace("''", "'").TrimEnd('_'); DataSet ds = new DataSet(); OleDbDataAdapter d = new OleDbDataAdapter("SELECT * from [" + name + "]", strConn); d.Fill(ds); DataTable dt = ds.Tables[0].Copy(); dt.Namespace = name; myDataset.Tables.Add(dt); } catch (Exception e) { } return myDataset; 
+4
source

http://npoi.codeplex.com

I use it myself on a 64-bit server with IIS 6.0. Not the easiest to use, but it works fine (fast, reliable, no office installed on the server, etc.).

+1
source

Have you thought about giving the Open XML SDK a try?

0
source

Source: https://habr.com/ru/post/1304988/


All Articles