I am working on a report to move data from table to reports in CSV.
Below is my SQL Server database that has column values as below, in non-english characters such as ü, ç ,é. And i have provided CSV output generated. The code which I am using also I have pasted below. 1st image is database data. 2nd image is Excel report data.
I have below code written.
public static byte[] GetMemoryStream<T>(List<T> data) where T : class
{
Logger.Debug("Inside GetMemoryStream(), step 7");
using (var mem = new MemoryStream())
using (var writer = new StreamWriter(mem))
using (var csvWriter = new CsvWriter(writer, System.Threading.Thread.CurrentThread.CurrentCulture)) // System.Threading.Thread.CurrentThread.CurrentCulture
{
var options = new TypeConverterOptions { Formats = new[] { "yyyy/MM/dd HH:mm:ss" } };
csvWriter.Configuration.TypeConverterOptionsCache.AddOptions<DateTime>(options);
csvWriter.Configuration.Delimiter = ",";
csvWriter.WriteHeader<T>();
csvWriter.NextRecord();
csvWriter.WriteRecords(data);
writer.Flush();
var result = Encoding.Unicode.GetString(mem.ToArray());
//Console.WriteLine(result);
return Encoding.Unicode.GetBytes(result);
// return mem.ToArray();
}