ASP가 Excel로 데이터를 가져온 후 중국어 문자가 깨져서 나타납니다. ? 해결 방법
저자:Eve Cole
업데이트 시간:2009-06-25 17:44:35
질문: ASP가 Excel로 데이터를 가져온 후 중국어가 왜곡되어 표시됩니까? ? 해결 방법
<!--#include 파일="function/connect.asp" -->
<!--#include 파일="function/function.asp" -->
<%
Response.Charset = "UTF-8"
'앞서 포함된 파일은 이며, 데이터베이스에 연결하려면 이 파일을 수정하여 다른 라이브러리에 연결해야 합니다.
sql1="select * from apply " '여기에 "SESECT * FORM CAI WHERE 성별='여성'"과 같이 EXCEL을 출력하는 쿼리 문이 있습니다.
filename="excel4.xls" '출력할 EXCEL 파일의 파일 이름입니다. 위 두 문장만 변경하면 되며 다른 내용은 변경하지 마세요.
Excel(FILENAME,sql1)을 호출합니다.
conn=아무것도 설정하지 않음
function ReadText(FileName) '파일을 읽는 함수입니다.
'response.write 서버.MapPath(파일 이름)
'응답.끝
set adf=server.CreateObject("Adodb.Stream")
adf와 함께
.유형=2
.LineSeparator=10
.열려 있는
.LoadFromFile(서버.MapPath(파일 이름))
.Charset="GB2312"
.위치=2
ReadText=.ReadText
.취소()
.닫다()
다음으로 끝나다
광고 설정 = 없음
함수 종료
sub SaveText(FileName,Data) '파일을 쓰는 함수입니다.
fs= createobject("scripting.filesystemobject")를 설정합니다.
ts=fs.createtextfile(server.MapPath(파일 이름),true) 설정
ts.writeline(데이터)
ts.닫기
설정=아무것도 없음
fs=아무것도 설정하지 않음
서브 끝
sub toexcel(filename,sql) 'SQL 문과 FILENAME을 기반으로 생성된 EXCEL 파일입니다.
rs=Server.CreateObject("ADODB.RecordSet")를 설정합니다.
'응답.SQL 쓰기
'응답.끝
rs.SQL 열기,objconn,1,1
TOEXCELLR="<테이블 너비='100%'><tr >"
myfield=rs.fields 설정
희미한 필드 이름(50)
i=0에서 myfield.count-1까지
toexcellr=toexcellr&"<td class=xl24>"&MYFIELD(I).NAME&"</td>"
필드 이름(i)=myfield(i).name
myfield(i).type=135이면 datename=datename&myfield(i).name&","
다음
toexcellr=toexcellr&"</tr>"
rs.eof가 아닌 동안 수행
toexcellr=toexcellr&"<tr>"
i=0에서 myfield.count-1까지
if instr(datename,fieldname(i)&",")<>0 then
그렇지 않은 경우 isnull(rs(fieldname(i)))
TOEXCELLR=TOEXCELLR&"<td class=xl25 ><p align='left'>"&formatdatetime(rs(필드 이름(i)),2)&"</p></td>"
또 다른
TOEXCELLR=TOEXCELLR&"<td class=xl25 ><p align='left'> </p></td>"
종료하면
또 다른
TOEXCELLR=TOEXCELLR&"<td class=xl24 >"&rs(필드 이름(i))&"</td>"
종료하면
다음
toexcellr=toexcellr&"</tr>"
rs.movenext
고리
RS.닫기
toexcellr=toexcellr&"</table>"
tou=readtext("tou.txt")
di=readtext("di.txt")
toexcellr=tou&toexcellr&di
savetext(파일 이름,toexcellr)를 호출합니다.
서브 끝
%>
<html>
<머리>
<meta http-equiv="refresh" content="3;URL=<%=filename%>">
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>EXCEL 파일 생성</title>
</head>
<본문>
EXCEL 파일을 생성하는 중....
</BODY>
</HTML>
답변:
EXEC master..xp_cmdshell 'bcp "SELECT * FROM 라이브러리 이름.dbo.apply 여기서 성별=여성" 쿼리아웃 "excel4.xls" -c -q -S"서버 이름" -U"사용자 이름" -P"비밀번호"'
이 방법을 사용하여 문자가 깨지지 않고 Excel로 내보낼 수 있습니다. SQL 데이터베이스를 사용해 보세요.