Solved

Coldfusion reading Excel file translates ñ into n

Posted on 2016-07-28
4
80 Views
Last Modified: 2016-07-29
I am reading an excel file using <cfspreadsheet action="read" src="#theFile#" query="data" headerrow="1">. However,letter ñ in data is converted to n in query="data".

How can I prevent translation from ñ to n
0
Comment
Question by:Errol Farro
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 52

Expert Comment

by:_agx_
ID: 41733499
Worked okay for me.

1. Can you upload a sample .xls that causes a problem on your end?
2. What is your CF version? <cfdump var="#server#">
0
 

Author Comment

by:Errol Farro
ID: 41733652
You are right !!! CFSPREADSHEET reads the ñ character

Further analyses in the code revealed the following

When I create a CSV containg the ñ character, the ñ is shown when the CSV file is opened with Notepad
However, when opening the CSV file with Excel, the ñ is converted to ñ


EXAMPLE

Opened with NOTEPAD
===============
Jeandru Castañeda

When opened with Excel
======================
Jeandru Castañeda


Code used to create CSV file is
            <cfsetting showDebugOutput="No">
            <cfheader name="Content-disposition" value="attachment;filename=#fileNameCsv#">
            <cfcontent type="UTF-8">
                <cfoutput>#word#</cfoutput>
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 41733824
Hm... seems like Excel may be having a problem with the charset.  Makes sense in a way since the download isn't actually returning a real Excel file, but simple text.  Try returning binary instead. Just convert the csv string into bytes and use the "variable" attribute:

<!--- For DEMO ONLY --->
<!--- IMPORTANT: The charset for your JVM may differ --->
<cfprocessingdirective pageEncoding="utf-8">
<cfset word = "Jeandru Castañeda">
<cfset binaryText = charsetDecode(word, "windows-1252") >

<cfheader name="Content-Disposition" value="attachment;filename=test.csv"> 
<cfcontent type="text/csv;" reset="true" variable="#binaryText#">

Open in new window


It is important to use the correct charset when decoding the string or the results will be wrong.  If you not sure what that is, check the default charset using:

<cfset defaultCharset = createObject("java", "java.nio.charset.Charset").defaultCharset()>
<cfdump var="#defaultCharset.toString()#">

Open in new window

0
 

Author Closing Comment

by:Errol Farro
ID: 41735144
Many thanks !!!!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question