WEB开发网
开发学院WEB开发ASP asp将数据导入excel后,中文出现乱码?怎么解决?... 阅读

asp将数据导入excel后,中文出现乱码?怎么解决?

 2008-09-11 12:06:09 来源:WEB开发网   
核心提示: set fs= createobject("scripting.filesystemobject")set ts=fs.createtextfile(server.MapPath(FileName),true)ts.writeline(data)ts.closeset

 set  fs=  createobject("scripting.filesystemobject")  
     set  ts=fs.createtextfile(server.MapPath(FileName),true) 
     ts.writeline(data) 
     ts.close 
     set  ts=nothing 
     set  fs=nothing 
 end  sub 
  
 sub  toexcel(filename,sql)  

'这是一个根据SQL语句和FILENAME生成EXCEL文件 

   Set  rs=Server.CreateObject("ADODB.RecordSet")  
    'Response.Write   sql 
   'response.end 
   rs.Open  sql,objconn,1,1 
   TOEXCELLR="<table  width='100%'><tr  >" 
   set  myfield=rs.fields 
   dim  fieldname(50) 
   for  i=0  to  myfield.count-1 
      toexcellr=toexcellr&"<td  class=xl24>"&MYFIELD(I).NAME&"</td>" 
      fieldname(i)=myfield(i).name 
      if  myfield(i).type=135  then  datename=datename&myfield(i).name&"," 
   next 
   toexcellr=toexcellr&"</tr>" 
   do  while  not  rs.eof 
     toexcellr=toexcellr&"<tr>" 
     for  i=0  to  myfield.count-1  
       if  instr(datename,fieldname(i)&",")<>0  then 
         if  not  isnull(rs(fieldname(i)))  then 
            TOEXCELLR=TOEXCELLR&"<td  class=xl25  ><p  align='left'>"&formatdatetime(rs(fieldname(i)),2)&"</p></td>" 
         else 
            TOEXCELLR=TOEXCELLR&"<td   class=xl25  ><p  align='left'> </p></td>" 
         end  if 
       else 
          TOEXCELLR=TOEXCELLR&"<td  class=xl24  >"&rs(fieldname(i))&"</td>" 
       end  if 
     next 
     toexcellr=toexcellr&"</tr>" 
     rs.movenext 
   loop 
   rs.close 
   toexcellr=toexcellr&"</table>" 
   tou=readtext("tou.txt") 
   di=readtext("di.txt") 
   toexcellr=tou&toexcellr&di 
   call  savetext(filename,toexcellr) 
 end  sub 
 %> 
 <html> 
 <head> 
 <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> 
 <BODY>

正在生成EXCEL文件.... 

 </BODY> 
 </HTML>

答:

EXEC  master..xp_cmdshell  'bcp  "SELECT  *  FROM  库名.dbo.apply  where  性别=女"  queryout  "excel4.xls"  -c  -q  -S"服务器名"  -U"用户名"  -P"密码"' 

我用这种方法导出到excel没有出现乱码,你试下吧,sql数据库

上一页  1 2 

Tags:asp 数据 导入

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接