Microsoft Excel mangles Diacritics in .csv files?

后端 未结 22 1714
粉色の甜心
粉色の甜心 2020-11-22 05:02

I am programmatically exporting data (using PHP 5.2) into a .csv test file.
Example data: Numéro 1 (note the accented e). The data is utf-8 (

22条回答
  •  名媛妹妹
    2020-11-22 05:31

    Writing a BOM to the output CSV file actually did work for me in Django:

    def handlePersoonListExport(request):
        # Retrieve a query_set
        ...
    
        template = loader.get_template("export.csv")
        context = Context({
            'data': query_set,
        })
    
        response = HttpResponse()
        response['Content-Disposition'] = 'attachment; filename=export.csv'
        response['Content-Type'] = 'text/csv; charset=utf-8'
        response.write("\xEF\xBB\xBF")
        response.write(template.render(context))
    
        return response
    

    For more info http://crashcoursing.blogspot.com/2011/05/exporting-csv-with-special-characters.html Thanks guys!

提交回复
热议问题