Update an excel sheet on Windows server 2012 with C# - c#

I am writing an application where we need to update an existing Excel sheet through our system. I was able to do so on my local machine with OleDbConnection but when i deploy the application on server it gives me "operation must use an updateable query"
error on Windows server 2012.
I know its not recommended to install MS Office on Server and thats why its causing the issue. Any one has an idea whast the work around for this problem.
Do i have to give permission to my .net application so it can update the excel file or its something else?
Thanks in Advance.

I know its not recommended to install MS Office on Server
Last I checked, it is also a violation of the license terms (though that may have changed)
As you note, there are many reasons it is unwise to deploy Office to a server environment.
If you are using the newer (2007+) .xlsx file format exclusively, you can use the open source EPPlus library for most common Excel tasks. It is free, straightforward to use, and is designed to work on a server.
EPPlus is a .net library that reads and writes Excel 2007/2010 files using the Open Office Xml format (xlsx).

Related

Error when creating Excel file from asp.net

I am trying to create an excel file using c#. My code is working fine on windows server 2008 but I am getting error in window server 2012 R2, iis server 8.5, ms office 2007 standard.
Its telling me error on line
oWB = (Excel._Workbook)(oXL.Workbooks.Add(Excel.XlWBATemplate.xlWBATWorksheet));
error: [COMException (0x800a03ec):microsoft office can not save or open more documents.
You are trying to create an Excel file
using COM automation
from an ASP.NET application.
This combination is officially unsupported by Microsoft:
Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.
Thus, if it worked so far on your Windows Server 2008, it was a mere coincidence. You have been lucky. It's not something you should do on a production system.
To create an Excel file from ASP.NET, use one of the various other solutions available:
Create Excel (.XLS and .XLSX) file from C#
(Personally, I have good experience with SpreadsheetLight, but any of the other solutions is fine as well.)
It's possible that it isn't a problem with your code since it works fine with windows server 2008. You can try this registry hack, but keep in mind that wrong registry modification can be fatal so you might want to create restore point or backup of your registry:
Run > regedt32
Fix the value of: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
In your User Shell Folders select Cache key and assign it to your own directory
There are also solutions I found for your problem without registry modification, visit this link or this one, it might help you. If none of these things work for you try googling "microsoft office can not save or open more documents" and check problems related to the excel itself. Once again, I assume the problem is not inside your code.

Will I require MS Excel installed on the server if I am generating Excel file using NetOffice?

I am trying out both NetOffice and NPOI for to use in an ASP.NET project.
I am making an ASP.NET web site where on click of a button, I want to generate an Excel file in a password protected state and send it to the client to download it.
But I want to know whether, will I require MS Excel installed on the server?
OR Is there a way where I can make this work on a server where MS Excel is NOT installed?
Also what are other pre-requisites for both these APIS?
I basically have to identify which of these APIs will work for me in a server without Microsoft Excel installed in it.
Please check documentation: http://netoffice.codeplex.com/documentation at question
What do I have to do to deliver my application with NetOffice?
Nothing except copying the needed assemblies to the target system. You don't need a registration or something like that with the exception of COMAddIns. Managed COMAddins generally have to be registered via the .Net Utility RegAsm.exe or the Windows Installer do that or you.

Read excel file with c# in 64-bit pc with Office 2003

I have a desktop application which has to read an excel file (either .xls or .xlsx).
When the application is installed in a Windows 7 pc with Office 2003 i cant read the excel file using Microsoft.ACE.OLEDB.12.0. I have the message that Microsoft.ACE.OLEDB.12.0 is not registered.
Using Microsoft.JET.OLEDB.4.0. doesnt help either.
So how can we read the excel file? I know one option is to build my application forcing it to compile to (x86) so it runs as a 32-bit application.
Ok, supposing i dont want to do so, is there any other option?
Thanks for any answers. Any comments are welcome!
You need the 64-bit JET/ACE driver installed:
http://www.microsoft.com/en-us/download/details.aspx?id=13255
Sounds like a job for Npoi. Stand alone library that can work with xls and xlsx files. No need to use those Jet libraries.
Ok, that will involve a bit of work, but you remove a dependency from something you can't control on user's machine.

C# Console App with Excel Interop hangs as a scheduled task on Windows scheduler/ActiveBatch

I have a C# application that opens an Excel file on a network drive, reads data and writes to a database. I can run it manually from a batch file, but it isn't working when I run the batch file from Windows Scheduler or ActiveBatch. I don't actually get an error - the job just hangs when it tries to open the Excel workbook (not when it opens the application).
I am running under the same user credentials both when I run manually and from a scheduler. I'm using .NET 3.5 on Windows Server 2003 Enterprise SP2 with Office 2007.
I've tried the "Ogawa Hack" described here, and I've tried using a level of indirection by writing another batch file that would be run by the scheduler and would call the original file. Neither worked.
Any other ideas I can try?
Since your application will probably run on a server, I would recommend not using Excel Interop for this task. There are free .NET libraries available, which don't require Excel to be installed. For the older Excel <= 2003 format look here
http://jexcelapi.sourceforge.net/
(in the files section you will find a .NET port of this Java lib). For the newer XML based formats, you can use this one:
http://excelpackage.codeplex.com/

using ms office com objects in other systems without have office installed

i wrote a app for reading excel files.i had to add some references to Microsoft office Com Objects.
it worked good in my system,but when i wanted to use it in other system in which does`t had ms office installed ,
i encounter a problem.i also carried dll files that has been added to project . what should i do ?
In order to use the relevant object libraries you'll have to make sure that Office (Excel in your case) is installed on your client machine. If you have the option I'd suggest to switch to the Open Office XML format anyways. I recently had a similar problem with MS Word and the +work to switch to the new format has def. payed of.
Check MS Open XML SDK
Performace++ and not depending on Office installed...
The Office COM objects depend on Office. You should either arrange for Office to be installed on the other systems, or use a component for reading Excel files that doesn't need Excel installed, such as the ODBC Excel driver or a third-party Excel file reader.

Categories