问题
Got a problem with reading Excel files in C# The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine.
, same for 'Microsoft.ACE.OLEDB.12.0'
. that only occurs when I run my app on IIS. Running it locally on the machine where IIS is running works fine.
The machine in question runs on Win2003 R2 Enterprise x64. I develop in VS2010, ASP.Net 4.0.
It looks like there are 2 types of solutions to this problem: either install something (preferred) or switch to 32bit mode. I'd like to understand the implications of both solutions because there are other apps running on these servers and changing servers takes a lot of time and is very painful.
- Can installation of Microsoft Access Database Engine 2010 Redistributable change the situation? Maybe I should install another version/something else? Source: http://www.arboundy.com/2010/11/the-microsoft.ace.oledb.12.0-provider-is-not-registered-on-the-local-machine/
- Does following the instructions on http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/405f5bb5-87a3-43d2-8138-54b75db73aa1.mspx?mfr=true mean that all applications on this server will run in 32bit mode? Is it necessary to do it if I change the settings of my application from 64 to x86? My current configuratios is "Any CPU", what do I lose if I set it to 32bit?
- Edit: there seem to be a third type of solution, to put a dll directly in my app. Is it a good soluion? Which dll it should be?
回答1:
Hi I am working with Excel at the moment in a project, from what I know adding the dll to the project is fine especially if you have no control over what you can install on the server. I know of a large project that does it like that. Microsoft recommend installing Excel on the deployment server and using Interops, which sound like what you are trying to do.
I wasn't able to install excel onto our deployment server because we have to share it with other projects so I used EP Plus which is available on nuget and extremely easy to set up and use. It took less than an hour to have it generating Excel files. The only drawback with it is that it only generates xlsx files which are the newer type of excel files.
This is an easier approach and it may be easier and suitable for your project. There's loads of sample code on their website if you want to check it out. This is just another option for you, hopefully it is useful to you.
来源:https://stackoverflow.com/questions/17022224/how-to-enable-reading-c-sharp-excel-files-on-iis-reading-them-locally-on-the-ma