First off, if you don't care about formatting the cells in the new excel document, then you will be done in about 30 seconds flat. If you want to format the cells, you will need to spend a bit more time and take a look at the excel xml schemas and explanations on the msdn site.
The solution can easily be adapted to export asp.net controls such as the datagrid. I have used the HttpContext class to stream the excel document rather than a build, store and offer up method to keep things simple in this example.
C# ASP.NET 3.5 Full Source Code click here
The code works as follows.
- Grab the data into a .NET data reader
- Build XML document based on MS-Excel XML schemas to hold Excel workbook and style sheets
- Inject Table object into XML document to map data to Excel sheet object
- Stream document using the .NET HttpContext class
No comments:
Post a Comment