I have a situation where I need to email a formatted excel spreadsheet to a CSR when a user clicks a button on my site.
I am doing this by taking an HTML table on my site and saving that as an excel spreadsheet that gets presented to the user. I'm using the code below to do this and it works great for the formatting:
Problem is, this doesn't allow me to email the result to my CSR, it only shows it to the user.
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
this.EnableViewState = false;
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
How can I get it so that I can email it to my CSR? I was thinking I could write the file to disk and then use my existing code to send the file as an attachment, but I can't get it to properly open in Excel when I write it out.
If instead of using the response.Write and use this instead:
I get a disk file containing the table (which is what I would expect) but when I open it in excel, i get nothing displayed.
StreamWriter writer = File.AppendText(Server.MapPath("~/Temp/fileEName.xls"));