1

I'm attempting to export international characters from query to csv. Output to the browser works fine, as does writing to Excel using CFSPREADSHEET.

I have the following set up:

  • The datasource connection uses JDBC
  • Table fields are nvarchar

Rendering the file is as follows:

<cfset filepath="c:/test.csv" />
<cfloop query="q">
  <cfset string = "" />
  <cfset string = listAppend(string, q.fieldname) />
  <cffile action="append" file="#filePath#" output="#string#" charset="windows-1252" />
</cfloop>
<cffile action="readbinary" file="#filePath#" variable="bin" charset="windows-1252"> 
<cffile action="delete" file="#filePath#" /> 
<cfheader name="Content-Disposition" value="attachment; filename=Output.csv" charset="windows-1252"> 
<cfcontent type="text/plain" reset="true" variable="#bin#" />

However, certain characters are not converting properly. For example:

  • Jørgen shows as Jørgen
  • Sälzler shows as Sälzler

Update - Adding charset="windows-1252" did solve a majority of the bad conversions including the above examples. The following still do not convert

  • Krčobić shows Kr?obi?
  • Mirosław shows Miro?aw
  • Bożek shows Bo?ek
justacoder
  • 2,684
  • 6
  • 47
  • 78
  • 1
    The `cffile` tags writes to the file using the default character set of the JVM (can be set in cfadmin). Try using the charset attribute like `charset="windows-1252` – Bernhard Döbler Nov 17 '17 at 13:18
  • That solved a majority of the characters! The name, for example, Krčobić still shows `Kr?obi?` – justacoder Nov 17 '17 at 18:09
  • Did you try [adding a BOM](https://stackoverflow.com/a/47360000/8895292)? Worked for me with Krčobić. – SOS Jan 17 '18 at 21:47

0 Answers0