[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 654
  • Last Modified:

how to write special characters to an excel file in C#.Net

I have a text which contains special Characters: "création des motifs"
I need to write this to an excel file. This is not being written correctly.
Can anyone please help...
StreamWriter objFSOFile = null;
string strData = null;
string strPath = null;
objFSOFile = CreateStatFile("PROD.CSV", ref strPath);
strTitle = "création des motifs";
PrintFile(ref objFSOFile, strTitle);
 
public static StreamWriter CreateStatFile(string strFile, ref string strPath)
{
       System.IO.StreamWriter createStatFileReturn = null;
       FileInfo objFSO = null;
        if (!(Directory.Exists(@"C\PROD_CI\")))
            {
                Directory.CreateDirectory(@"C\PROD_CI\");
            }
            strPath = @"C\PROD_CI\" + strFile;
            objFSO = new FileInfo(strPath);
            if (objFSO.Exists)
            {
                objFSO.Delete();
            }
             createStatFileReturn = objFSO.CreateText();
             objFSO = null;
              return createStatFileReturn;
}
 
public static void PrintFile(ref StreamWriter objFSOFile, string strData)
{
       objFSOFile.WriteLine(strData);
}

Open in new window

0
MPakeezah
Asked:
MPakeezah
1 Solution
 
MPakeezahAuthor Commented:
The solution is while creating the file itself, create it as encoding UTF8.
createStatFileReturn = new StreamWriter(objFSO.Create(), System.Text.Encoding.UTF8);
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now