When trying to export data from a C# GridView to Excel, all newline ("\n") and return carriage ("\r") are being disregarded and removed on the export.
For example, when exporting this text "testing1\r\n\r\ntesting 2\r\n\r\ntesting 3", it exports like this:
I'd like it to be this
Here is the code I am using, I don't know what else to try. I've been looking for answers for some time now with no solution other than possibly switching to export to CSV instead although that is not ideally what I want.
var gridView = new GridView { DataSource = content };
Response.ClearContent();
gridView.DataBind();
Response.Buffer = true;
Response.AddHeader("content-disposition", $"attachment; filename={fileName}.xls");
Response.ContentType = "application/ms-excel";
Response.Charset = "";
StringWriter objStringWriter = new StringWriter();
HtmlTextWriter objHtmlTextWriter = new HtmlTextWriter(objStringWriter);
gridView.RenderControl(objHtmlTextWriter);
Response.Output.Write(objStringWriter.ToString());
Response.Flush();
Response.End();