I’m generating a report via Linq to SQL and displaying it on the website.
I need to save the report in MS Excel (or .csv) and email it to user.
Any ideas on how to save it as Excel or .csv ?
.NET 3.5 / C#
EDIT:
the Gridview hack works perfect. If you use AJAX on the page, make sure you add a PostBaseTrigger to your Update Panel to cause FULL POSTBACK, it won’t work otherwise.
<asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Button ID="Button1" runat="server" Text="Export Grid" onclick="Button1_Click" /> </ContentTemplate> <Triggers> <asp:PostBackTrigger ControlID="Button1" /> </Triggers> </asp:UpdatePanel>
I’ve also found a Library to Generate Excel XML Workbooks in .NET, however it’s not as simple as accepted solution.
This gridview hack is the simplest solution I’ve found.