5

I'm trying to develop a c#/asp.net application to extract data from a SQL server and have it formatted in an excel spreadsheet. I have been practicing with excel object model and recently stumbled upon this: http://support.microsoft.com/kb/257757 Considerations for server-side Automation of Office

From what I understand I really can't use Excel Object models? And if not what are other solutions/advice besides whats suggested in this article and 3rd party apps I can use?

nhat
  • 1,159
  • 5
  • 21
  • 40
  • Once the Excel speadsheet has been formatted, do you then want to push it to the user? What version of .NET are you using? – Jethro Aug 27 '11 at 16:11
  • Sorry for the late reply. Using .net 4 and yea try to push to a web front end. The spreadsheet format would already be formatted and one of the backend will have to populate it correctly in the preformatted spreadsheet. Then the user can download the spreadsheet with the data in it. – nhat Sep 07 '11 at 19:48

3 Answers3

5

From that article:

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.

What this means is that Microsoft won't explicitly prevent you from trying (the licensing allows you to try.) However, if there is a problem, it's up to you to figure out how to fix it.

There is a better option:

Create Excel (.XLS and .XLSX) file from C#

This will allow you to create the file for download without having to use Excel automation on the server side.

Community
  • 1
  • 1
Dave Swersky
  • 34,502
  • 9
  • 78
  • 118
3

I can recommend the SpreadsheetGear library, it has all the Excel functions in one managed dll:

http://www.spreadsheetgear.com/

Tobias Schittkowski
  • 2,221
  • 2
  • 16
  • 25
2

You 'can' use Excel automation on the server side. However you will be breaching licences ,may run into security problems and generally experience other odd behaviour, especially if you have more than one user using it at a time. I would suggest that you dont do it.

  1. If the data you want to write is simple enough just do it as a csv

  2. If not and you really have to write a spreadsheet look for a 3rd party component that writes excel files. I only know of one off the top of my head and thats Aspose.Cells, but that is quite expensive.

kmcc049
  • 2,783
  • 17
  • 13
  • Are there any websites you recommend to learn to use .CSV file solutions? – nhat Aug 27 '11 at 17:45
  • writing a csv is simply a matter of creating a string to represent the data. If there is a lot of data use a stringwriter to stream the data in a more efficient manner. – kmcc049 Aug 28 '11 at 08:07