I ran into this problem, but the difference is that I do not have access to the sheet in the code, because I only pass it to memystream and then create the file as a CSV type.
foreach (var s in propertyValues) streamWriter.WriteLine(s); streamWriter.Flush(); memoryStream.Seek(0, SeekOrigin.Begin);
I use it here.
subjExportData.FileStream = stream; subjExportData.FileName = string.Format("SubjectExport_{0}.csv", DateTime.Now.ToString("ddMMyyyy_HHmm"));
Therefore, the proposal to install text wrapping or cells is not an option. Having received it using the above answer, add a double quote before and after the text / line. Replacements must be processed when the sentence contains a double quote. Thus, this solution processes a new line, a comma, and double quotation marks inside a sentence or paragraph.
if (value.ToString().Contains("\n")) { value = value.ToString().Replace("\n", "\r\n"); sb.Append('"'+ value.ToString().Replace(@"""", @"""""") + '"'+ ","); }
source share