It was not possible to automate excel on your server, which is not recommended, the easiest way is to use the line builder to create the required output, and then write it to HttpResponse, setting the content type to "text / csv", setting the corresponding header information.
Although this is not strictly an excel document, the user downloading the file will be asked to open it in excel if it is installed or, alternatively, any other spreadsheet editor.
The following snippet should catch you:
string docName = "MyExcelDoc" StringBuilder sb = new StringBuilder(); sb.AppendLine("AAAAAA"); sb.AppendLine("BBBBBB"); context.Response.ClearContent(); context.Response.ContentType = "text/csv"; context.Response.AddHeader("content-disposition", "attachment; filename=" + docName + ".csv"); context.Response.Write(sb.ToString()); context.Response.Flush();
source share