I've got a pretty simple web form which lets users pick reports, one specific report they want in xls with pretty formatting instead of CSV. I've whipped up the report using COM INTEROP with excel 2007. It works on my local machine and can write the file, but on the web server it fails with this error:
Microsoft Office Excel cannot open or save any more documents because there is not enough available memory or disk space.
• To make more memory available, close workbooks or programs you no longer need.
• To free disk space, delete files you no longer need from the disk you are saving to.
There is plenty of disk space on the server, so I don't think it's that - could this be a permissions issue? I've escalated ASPNET and NETWORK SERVICE accounts to have write and modify access to the folder we're saving reports to - but still no joy. Any ideas?
Do I need to invoke the com object with a specific user account, or maybe elevate the interop calls to administrator account? Any idea how to do this?
Sorry guys, sorted it.
Serge you are halfway there. I ended up running Excel as administrator:
in component services, select excel application and choose admin as the user that runs it. Seems to work okay for the week of use it'll get :)
Thanks all!
SpreadsheetGear for .NET will let you save xls and xlsx workbooks directly to a response stream with IWorkbook.SaveToStream. It is all safe managed C# code so there is no need to run anything as admin and you will not run into the problems that Excel COM Interop bring on an ASP.NET server.
You can see some simple ASP.NET Excel Reporting samples (C# and VB) using SpreadsheetGear here and download the free trial here.
Disclaimer: I own SpreadsheetGear LLC
you might want to use impersonation for your ASPNET process; here's some info and example on how to do this: killing a win process from a C# console application: How do I set permissions? more info on impersonation How to implement impersonation in an ASP.NET application
Related
I have created a merge excel program in my application using Microsoft.Office.Interop.Excel. But when deployed on IIS server I am getting error. Regarding that error I searched many articles and tried but got no successfs. So please can you verify this?
It is required.
But, you should not use Office interop on a server. The problem is that Office apps require a graphical user session to work properly. On the other hand, Windows service apps and IIS run without one. This is officially not supported and not recommended. If you do, you will encounter random crashes and resource leaks.
If you want to generate or modify Excel files, use OpenXML SDK.
EDIT: You may want to use Spreadsheet Gear. I can recommend it from personal experience in a web-app that manipulated existing Excel sheets with complex formulas.
I am using FileUpload control of asp.net and uploading the excel with some data. I can't save it in some folder. I can have stream of excel sheet file or I can have Blobstream after uploading excel as a blob. Now I want to convert that excel sheets 1st sheet to datatable so how shall I do that? I am using C# .NET. I don't want to use Interop library. I can use external libraries. Oledb connection is getting failed since I don't have any physical path of excel as a data source. I tried following links:
1) http://www.codeproject.com/Articles/14639/Fast-Excel-file-reader-with-basic-functionality
2) http://exceldatareader.codeplex.com/
Please help.
Depending on the type of Excel file you can use the examples you posted or go for the OpenXML alternative (for xlsx files): http://openexcel.codeplex.com/
Now, the problem with the physical path is easy to solve. Saving the file to blob storage is great. But if you want, you can also save it in a local resource to have it locally. This will allow you to process the file using a simple OleDb connection. Once you're done with the file, you can just delete it from the local resource (it will still be available in the blob storage since you also uploaded it there).
Don't forget to have some kind of clean up mechanism in case your processing fails. You wouldn't want to end up with a disk filled with temporary files (even though it could take a while before this happens).
Read more on local resources here: http://msdn.microsoft.com/en-us/library/windowsazure/ee758708.aspx
You should use OpenXML SDK which is an officially suggested way of working with MS Office documents - http://www.microsoft.com/download/en/details.aspx?id=5124
I first created local storage as per the link:
http://msdn.microsoft.com/en-us/library/windowsazure/ee758708.aspx
suggested by Sandrino above. Thanks Sandrino for this. Then I used oledb connection and it gave me an error "Microsoft.Jet.Oledb.4.0 dll is not registered". Then I logged on to the azure server and in the IIS changed app pool configuration for 32-bit. To change app pool to 32-bit refer the following link:
http://blog.nkadesign.com/2008/windows-2008-the-microsoftjetoledb40-provider-is-not-registered-on-the-local-machine/
The approach you followed is not the correct one, as you said you logged on to azure and changed, the VM which is running on azure is not the permanent one for you. For any updates you are going to get new VM machine. you might have to find turn around for this, instead of modifying manually. You can make use of the startup tasks in your azure app. See the link below it may help you.
http://msdn.microsoft.com/en-us/library/gg456327.aspx
I have ASP.NET web service, which is creating file in XML table format.
I need to convert this file into Excel 2003 format.
What can I use instead of Microsoft.Interop library?
UPDATE: I also need to copy format from the original file.
you can read the data from xml using linq and then insert it on the run using linq to excel with the dll provided in the post above.
also take a look at this article i hope it helps
http://blogs.msdn.com/b/bethmassi/archive/2007/10/30/quickly-import-and-export-excel-data-with-linq-to-xml.aspx
Have you tried OpenXML? Here is an example
With Office 2007
Look here for Cell Formatting
I use ExcelLibrary
I think it's a very easy to use tool.
you can transform an XML string to an excel file in one method.
I also heared about NPOI, maybe give it a look also.
I've found the answer by myself.
I could not use different libraries, because I had to open file in XML Table format and resave it to Excel 2003 format.
Maybe my experience in this question will help someone. I used Windows Server 2008 with IIS 7.0 and Excel Library Microsoft.Office.Interop.Excel version 12.
Microsoft says, that using Interop DLL may cause unpredictable result, but it's NOT impossible.
The main problem of using Interop classes lies into access to launch DCOM applications by user, that starts web-service.
To make web-service works correct in my way I did next:
I opened "dcomcnfg" and disable authorization for all DCOM
components.
Another way is to find exactly your DCOM objects and give
permissions to local launch to the user, that starts the service.
Gave permissions to registry branch
HKEY_CLASSES_ROOT\CLSID\ID_OF_MICROSOFT_APPLICATION_CLASS
ID_OF_MICROSOFT_APPLICATION_CLASS = class, which contained in
web-server error while accessing to Interop DLL
It's very strange, but important: I created folder
for 86x: C:\Windows\System32\config\systemprofile\Desktop
for 64x: C:\Windows\SysWOW64\config\systemprofile\Desktop
Gave write permission to web-service user to all folders, which my
web-service use, including folder from item (3).
If your web-service works under NETWORK SERVICE try to change it to some local user, maybe it may help you.
I want to display and edit MS Excel File from client side using ActiveX COM object. The user would be allowed to edit the file and save it to local PC. Then It can be uploaded to remote server.
So, can you give me some example of displaying Word, Excel, Powerpoint etc document in Internet Explorer 8.0 using COM. I could not find such ocx files for that purpose . Can you help me finding it.
Thanks
Maksud
I think those controls would violate the MS Office distribution or EULA licensing agreements with Microsoft. Since an ActiveX control that emulates Word, Excel, PowerPoint would potentially give unlimited and anonymous users access to the software without paying for it. There's other Microsoft technologies that allow you to leverage the end-user's MS Offices licenses that allow them to save back to the web server. I think WebDAV used to be used (http://technet.microsoft.com/en-us/library/cc781730%28WS.10%29.aspx), I don't know what's out there now, but I'm sure there's a solution.
I wonder if the use of Google Docs would solve these issues. I'm pretty sure there's a way to leverage some sort of mix of Google Docs and the associated APIs to do something akin to what you are trying to do. I admit this isn't quite a perfect match for your goals.
This sounds like a use case that Office Live Workspace was created for. It's free, it's collaborative, and it allows you to determine sharing permissions.
I currently have a website (ASP.NET 3.5, IIS 7.0) that allows users to upload Excel files for processing.
Should I be concerned with viruses and malicious code being executed when the document is opened?
We are currently using the .NET Office.Interop assemblies to fetch the information from the document. The information isn't exactly tabular and requires a little bit of interrogation to get it into the required format.
Once the document has been uploaded it will be stored in the database, only when the document is inspected is it written to disk.
Are there any recommendations that would provide a secure implementation?
Using the xlsx (Open XML) file format will be safer than using xls or xlsm since xlsx workbooks cannot contain macros.
You might consider using a pure .NET component which does not use COM Interop or any native calls and does not require FullTrust. SpreadsheetGear for .NET is an example of such a component.
Disclaimer: I own SpreadsheetGear LLC
Sanitizing is the only way to be sure. Since it's not simply form input, you want to take extra precautions. The simplest method I can imagine is to nuke any binary-indicators, like control-characters.
As far as best practices, you can't really tell your users "Please don't hack me", so you have to have a certain level of trust (or give up on Excel files)... I would say if the first pass picks up any binary flags, incinerate it and throw a fairly obtuse error like "error in file format", etc.
But of course, your users will murder you they ever get that error for a good file.