Search code examples
c#mysqlexport-to-excel

How to fetch data from MySQL into Excel Unicode character in C#


my problem to occur when I try fetch data from MySQL to Excel.

I read more example in Internet, but not working.

I want in event "Form_Closing" it will save all MySQL export to Excel.

I've test create *.csv in localhost/phpMyAdmin to export data to Excel but character not support Unicode. It's broken like:

Character with Unicode is broken

And all cell with header display incorrectly. Thanks.


Solution

  • When you create the csv file in C#, you must specify the proper encoding like:

    System.IO.StreamWriter streamWriter = new System.IO.StreamWriter(
                             "file.csv", false, System.Text.Encoding.Unicode)