1

I've come across ExcelPackage and I found a couple of examples of using it, but none seem to work, they've all got some aspect, component missing or are for a different version of Visual Studio. I simply need to generate a .xls or .xlsx or even a .csv file, but as I am using a 3rd party server I can't use the Office .com objects. I have used SpreadsheetGear in the past which is expensive and as I am retired, I can't afford this sort of product.

If anyone has a working example of ExcelPackage or any other freeware offering, or can point me in the direction of one that has everything I need, it would be appreciated. A regular Web App rather than MVC would be preferred.

Peter C
  • 553
  • 2
  • 7
  • 19

2 Answers2

2

Take a look at Simplexcel by Michael Stum. It is designed around simplicity, is fully supported under ASP.net and should allow you to make simple, but extremely usable Excel cheats. You have an simple example available here.

Community
  • 1
  • 1
eandersson
  • 25,781
  • 8
  • 89
  • 110
  • This looks like it will do the job, but I am am new to this sort of thing and it is trying to save to the server. How do I get the file that is generated on the server to save to my local PC? I have looked around the net and I can only find examples of saving existing files, not on the fly generated files. – Peter C Mar 23 '13 at 13:36
  • Tthat is a bit outside of the scope of your original question. I would recommend opening a new question for taht, but you could probably do something like this. `MemoryStream stream = new MemoryStream(); wb.Save(stream, CompressionLevel.Maximum); return new FileStreamResult(stream, "application/vnd.ms-excel");` Basically storing the result in Memory, and then using `FileStreamResult` to return it in ASP.net. – eandersson Mar 23 '13 at 15:14
  • Ok, thanks eanderason. I will do just that. I am not using MVC and FileStreamResult is an MVC component, so need something for webforms. I suspect it is going to use HTTP handlers. – Peter C Mar 23 '13 at 16:07
  • You can do the same for WinForms. Would sending them as an email be an option? – eandersson Mar 23 '13 at 16:11
  • I can't use winforms, but an email would be a non-preferred option. I can't store the file though on the server. – Peter C Mar 23 '13 at 16:13
  • Ah, my bad misread your previous comment. I think this should be for ASP.net. I haven't really used plain ASP.net myself. ;) `Response.ContentType = "application/vnd.ms-excel"; Response.OutputStream.Write(stream, 0, stream.Length); Response.AddHeader("Content-Disposition", "attachment;filename=yourfile.xls");` http://stackoverflow.com/questions/1072814/c-sharp-asp-net-write-file-to-client – eandersson Mar 23 '13 at 16:23
  • If you start a new question I can probably try to show you some more extensive examples on how to send files through webforms using a stream in a plain `ASP.net`. – eandersson Mar 23 '13 at 16:28
  • Thanks, I will try this. I have started a new http://stackoverflow.com/questions/15589162/asp-net-webform-generated-excel-file-to-local-pc-and-not-server – Peter C Mar 23 '13 at 16:33
  • I updated my answer on your second question http://stackoverflow.com/questions/15589162/asp-net-webform-generated-excel-file-to-local-pc-and-not-server/15589598#15589598 with a complete example. =] – eandersson Mar 23 '13 at 17:31
0

Check out the Open XML SDK. This gives you the ability to generate and manipulate Office documents without using Office itself or the interop, and as such makes it a suitable approach from the server-side.

Mathias
  • 15,191
  • 9
  • 60
  • 92