2017-11-17 22 views
1

쿼리에서 csv로 국제 문자를 내보내려고합니다. CFSPREADSHEET을 사용하여 Excel에 쓰는 것과 마찬가지로 브라우저로 출력해도 문제가 없습니다.Nvarchar 데이터 형식을 CSV로 내보내기

내가 설정 한 다음 한 :

  • 데이터 소스 연결은 JDBC를 사용
  • 테이블 필드는 다음과 같이 파일을 렌더링

은 NVARCHAR이다 : 그러나

<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#" /> 

, 특정 문자가 제대로 변환되지 않습니다. 예를 들어 : - 위의 예제를 포함하여 나쁜 변환의 대부분을 해결했다 charset="windows-1252" 추가 업데이트

Sälzler로 Jørgen

  • Sälzler와 같이

    • 요르겐 보여줍니다. 다음은 여전히 ​​변환되지 않습니다.

      • Krčobić는 Kr? obi를 보여줍니다.
      • 는 Mirosław 보여줍니다 미로? 아
      • Bożek가 보? EK을 보여줍니다
  • +1

    'cffile' 태그는 JVM의 기본 문자 집합을 사용하여 파일에 기록합니다 (cfadmin에서 설정할 수 있음). 'charset = "windows-1252'와 같은 charset 속성을 사용해보십시오. –

    +0

    대다수의 문자가 해결되었습니다! 예를 들어 Krčobić의 이름이 여전히'Kr? obi? '입니다. –

    +0

    [BOM 추가] (https : //stackoverflow.com/a/47360000/8895292) Krčobić와 함께 나를 위해 일했습니다. – Ageax

    답변

    0

    기발한 Excel has issues with UTF8 CSV files. 한 가지 제안은 BOM가 함께 그것을 도움을 추가하는 것입니다,하지만 결과는 서로 다른 버전의 혼합된다. 자세한 내용은 전체 스레드를 참조하십시오.

    ... build file string .... 
    <cfset FileWrite(filePath, binaryDecode("EFBBBF", "hex"))> 
    <cfset FileAppend(filePath, string, "utf-8")> 
    
    <cfheader name="Content-Disposition" value="attachment; filename=Output.csv" charset="utf-8"> 
    <cfcontent type="text/plain" reset="true" file="#filePath#" deleteFile="false" />