Copy link to clipboard
Copied
HI
I have CF 9, try to query from DB with utf-8 chars. it show Ok on web page.
Then we tried to write to txt file so we can download and open the Excel.
the txt file shows &#... chars
Please help. I tried to google but can not find and help.
I really appreaciate.
I will buy you a Starbuck coffee.
<!--- Lets make the file, and put the first row of Column headings in --->
<cffile action="WRITE" file="#f_dir##f_name#" output="CamperType, FullName, LDName, MCNName, CamperID, Photo" addnewline="Yes" charset="windows-1252">
<cfloop query="camperList">
<cffile action="APPEND" file="#f_dir##f_name#" output="#camperTypeName#, #camperFullName#, #Ldname#, #mcnName#, #camperID#, #photoIDFile#" addnewline="Yes" charset="utf-8">
<!--- End the loop here --->
</cfloop>
<br>
<cfoutput>
<a href="reportDownload.cfm?FileName=#absolutefilepath#">Here is the file</a>
</cfoutput>
Copy link to clipboard
Copied
charset="windows-1252" charset="utf-8"
Any reason why you use "windows-1252"? I expected you to use UTF-8 charset everywhere.
In fact, I would suggest that you:
As a last resort (if all of the above fails), you could use the class org.apache.commons.lang.StringEscapeUtils to convert HTML entities. For example:
<!--- Lets make the file, and put the first row of Column headings in --->
<cffile action="WRITE" file="#f_dir##f_name#" output="CamperType, FullName, LDName, MCNName, CamperID, Photo" addnewline="Yes" charset="utf-8">
<cfloop query="camperList">
<cfset outputRowData = "#camperTypeName#, #camperFullName#, #Ldname#, #mcnName#, #camperID#, #photoIDFile#">
<cffile action="APPEND" file="#f_dir##f_name#" output="#convertHTMLEntity(outputRowData)#" addnewline="Yes" charset="utf-8">
<!--- End the loop here --->
</cfloop>
<br>
<cfoutput>
<a href="reportDownload.cfm?FileName=#absolutefilepath#">Here is the file</a>
</cfoutput>
<cffunction name="convertHTMLEntity" returntype="String">
<cfargument name="inputString" required="yes">
<cfset var conversionObject = createObject("java", "org.apache.commons.lang.StringEscapeUtils") />
<cfreturn conversionObject.unescapeHTML(arguments.inputString)>
</cffunction>
Copy link to clipboard
Copied
Did that help?