Home » excel » excel – Save CSV WITH BOM

excel – Save CSV WITH BOM

Posted by: admin April 23, 2020 Leave a comment

Questions:

I have asp page which creates csv file. The problem is that this csv file is created as UTF-8 WITHOUT BOM and when I open it, some signs are not visible correctly. What should I change to save it as UTF-8 WITH BOM? If I convert it to UTF-8 WITh BOM manially in notepad++, it works.

Thanks.

    Response.Clear
    Response.ContentType = "application/vnd.ms-excel; charset=UTF-8;"
    Response.AddHeader "Content-Disposition", "attachment; filename=goodsTransfer.csv"
    Response.Charset = "UTF-8"
    Response.Write "all my data"
    Response.end
How to&Answers:

Try:

Response.Write(ChrW(65279) & "all my data")

Answer:

The correct BOM for UTF-8 is:

Response.Write(ChrW(&HeF) & ChrW(&Hbb) & ChrW(&HbF) & "all my data")