ColdFusion XLS Export and Character Encoding

I "export" data from a page to Excel using an HTML table. The table looks great in the browser, but special Excel characters, such as apostrophes, trademark characters, etc., are incorrectly encoded. If I open the exported file in notepad and save it in ANSII encoding, and then open it in Excel, everything will look great.

I tried setting the page encoding in ColdFusion using cfcontent, setencoding and cfpagedirective until I got lucky. Any suggestions?

EDIT: As temporary work, erroneous characters can be deleted by saving the exported file to disk, opening it in Notepad, and then saving it again. Not really the best solution to the problem.

Regarding weird characters:

® becomes ®

™ becomes â <¢

becomes â € ™

+3
source share
6 answers

Is this a programming issue?

At least you can do as a programmer and provide some debugging information. Forget about the apostrophe, there are several different characters that you could mean; what should look like a trademark symbol in Excel: do you get 0, 1 or 2 characters? If non-zero, which character is displayed / displayed? Is it possible to use the CODE () function in a formula to tell us the internal code of the character (s) you see?

, . , , Notepad, , UTF-8, Excel , ANSI. cp1252 , .

: HTML? HTML - charset=UTF-8 - ? HTML .htm,.html - ? Excel? Excel: 2007, 2003, ?

-1

"Â", Excel, HTML, .

cfcontent : <cfcontent type="application/vnd.ms-excel> to: <cfcontent type="application/vnd.ms-excel; charset=windows-1252"> .

+1

HTML CSV " :

"value1","value2"

Java stringbuffer queryToCSV :

<cffunction name="queryToCSV" returntype="string" access="public" output="false">
    <cfargument name="query" type="query" required="true">

    <cfscript>
        var csv = createobject( 'java', 'java.lang.StringBuffer');
        var i = 1;
        var j = 1;
        var cols = "";
        var headers = "";
        var endOfLine = chr(13) & chr(10);
        if (arraylen(arguments) gte 2) headers = arguments[2];
        if (arraylen(arguments) gte 3) cols = arguments[3];
        if (not len( trim( cols ) ) ) cols = query.columnlist;
        if (not len( trim( headers ) ) ) headers = cols;
        headers = listtoarray( headers );
        cols = listtoarray( cols );

        for (i = 1; i lte arraylen( headers ); i = i + 1)
            csv.append( '"' & headers[i] & '",' );
        csv.append( endOfLine );

        for (i = 1; i lte query.recordcount; i= i + 1){
            for (j = 1; j lte arraylen( cols ); j=j + 1){
                if (isNumeric( query[cols[j]][i] ) )
                    csv.append( query[cols[j]][i] & ',' );
                else
                    csv.append( '"' & query[cols[j]][i] & '",' );

            }
            csv.append( endOfLine );
        }
        return csv.toString();
    </cfscript>
</cffunction>
0

charset="utf-8" CFFile? , charset="windows-1252"?

FYI: CF9 .xle( csv, real excel file!) CFSpreadsheet

0

-, Excel ? , 2007 (, , 2003 ), , -, (cp1252, , 100%).

, , , cfcontent - - :

<cfcontent type="application/vnd.ms-excel; charset=windows-1252">

If this is not the correct encoding, you can try some others, for example. iso-8859-1 or us-ascii. See http://livedocs.adobe.com/coldfusion/7/htmldocs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=ColdFusion_Documentation&file=00000232.htm for a complete list.

You can also check cfreport when you can generate excel files.

0
source

Source: https://habr.com/ru/post/1712606/


All Articles