Monday, May 02, 2005

Excel

Today i was asked to do the unthinkable, automate excel on the server to serve xls files to users. I cringe at this thought. Not only is automating excel dangerous on the server, it's also time consuming to built compless tables of data. The strings required in memory are expensive on server performance, not to mention if you get caught in an infinite loop (by forgetting to call MoveNext()).

I have done it though. I have managed to automate excel on the server by first creating a file using tabs, then before i serve it out, setting the following guys:

Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "filename=custom_export.xls"


This isn't so difficult. ContentType tells IE the file your downloading is an excel sheet, if you have excel installed, IE will take car of everything. The "Content-Disposition" tells IE the file name you want to use, otherwise they could save the document as anything, including a aspx page. The hardest thing to do is find these two gems and remember to set them. Once that's done, you can party on!

Now i am proud, i have pseudo automatted excel on the server, i'd rather do this with VSTO, but hey, i will settle for this now and convert to VSTO later.

TTYL,
C

0 Comments:

Post a Comment

<< Home