asp 导出excel 出现乱码

motefancysilver 2010-01-19 09:22:32
进行查询(asp代码),将查询结果导出excel,查询条件为所在乡镇,其中2个乡镇有数据,选择其中一个乡镇时,导出的数据都是对的,选择另一个时,导出的数据中文都变为了韩文,不知为什么??主要代码如下:
<meta content="text/html; charset=gb2312" http-equiv="Content-Type">

Response.Clear()
Response.ContentType = "application/vnd.ms-excel"

哪位大侠帮个忙....
...全文
380 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
小官 2011-08-18
  • 打赏
  • 举报
回复
开发语言:ASP,开发环境:dreamweaver

从sql 2000数据库查询出的结果以表格的形式显示在页面上,却不知道怎么通过导出按钮导入excel ? 哪位大侠如果有代码还请不吝指教下?如果有代码可以发给我吗?287168917@qq.com,不胜感激~!
zhoudan3986226 2010-01-22
  • 打赏
  • 举报
回复
我给你一个 我正在用的

SUB XLS()
dim rs,sql,filename,fs,myfile,x

Set fs = server.CreateObject("scripting.filesystemobject")
'--假设你想让生成的EXCEL文件做如下的存放
filename = Server.MapPath("Excel.xls")
'--如果原来的EXCEL文件存在的话删除它
if fs.FileExists(filename) then
fs.DeleteFile(filename)
end if
'--创建EXCEL文件
set myfile = fs.CreateTextFile(filename,true)

Set rs = Server.CreateObject("ADODB.Recordset")
'--从数据库中把你想放到EXCEL中的数据查出来
sql = ""&trim(request.form("SQL_TEXT"))&""
set rs=conn.execute(sql)
if rs.EOF and rs.BOF then
Response.Write "库里暂时没有数据!"
else
dim strLine,responsestr
strLine=""
For each x in rs.fields
strLine= strLine & x.name & chr(9)
Next

'--将表的列名先写入EXCEL
myfile.writeline strLine

Do while Not rs.EOF
strLine=""

for each x in rs.Fields
strLine= strLine & x.value & chr(9)
next
'--将表的数据写入EXCEL
myfile.writeline strLine

rs.MoveNext
loop
end if

rs.Close
set rs = nothing
SqlClose()
set myfile = nothing
IS_XLS=true
Set fs=Nothing
end sub
%>
motefancysilver 2010-01-22
  • 打赏
  • 举报
回复
up
wcwtitxu 2010-01-22
  • 打赏
  • 举报
回复

<%@ language="JScript" codepage="65001" %>
<%
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.URLEncode("abc.xls"));
%>
<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="ProgId" content="Excel.Sheet" />
<meta name="Generator" content="Microsoft Excel 11" />
<!--[if gte mso 9]><xml>
<x:ExcelWorkbook>
<x:ExcelWorksheets>
<x:ExcelWorksheet>
<x:Name>表名表名</x:Name>
<x:WorksheetOptions>
<x:DefaultRowHeight>285</x:DefaultRowHeight>
<x:Selected/>
<x:Panes>
<x:Pane>
<x:Number>3</x:Number>
<x:ActiveRow>2</x:ActiveRow>
<x:ActiveCol>1</x:ActiveCol>
</x:Pane>
</x:Panes>
<x:ProtectContents>False</x:ProtectContents>
<x:ProtectObjects>False</x:ProtectObjects>
<x:ProtectScenarios>False</x:ProtectScenarios>
</x:WorksheetOptions>
</x:ExcelWorksheet>
</x:ExcelWorksheets>
<x:WindowHeight>9090</x:WindowHeight>
<x:WindowWidth>11715</x:WindowWidth>
<x:WindowTopX>240</x:WindowTopX>
<x:WindowTopY>90</x:WindowTopY>
<x:ProtectStructure>False</x:ProtectStructure>
<x:ProtectWindows>False</x:ProtectWindows>
</x:ExcelWorkbook>
</xml><![endif]-->
<style type="text/css">td,th{font-size:12px; font-family:Arial,宋体;}</style>
</head>
<body>

<%
function w() { Response.Write(Array.prototype.slice.call(arguments).join('')); }
function forEach(collection, theFunction, scope) {
for (var e=new Enumerator(collection); !e.atEnd(); e.moveNext())
theFunction.call(scope, e.item());
}



function wRecordSet(rs) {
w("<table>");
w("<tr>");
forEach(rs.Fields, function(field) {
w("<th>", Server.HTMLEncode(field.Name), "</th>");
});
w("</tr>");
while (!rs.EOF) {
w("<tr>");
forEach(rs.Fields, function(field) {
w("<td>", Server.HTMLEncode(field.Value==null?'':field.Value), "</td>")
});
w("</tr>");
rs.MoveNext();
}
w("</table>");
}


!function() {
var conn = Server.CreateObject("ADODB.Connection");
conn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("x.mdb"));
var rs = conn.Execute("SELECT * FROM [tab]");
wRecordSet(rs);
rs.Close();
conn.Close();
}();

%>

</body>
</html>
motefancysilver 2010-01-22
  • 打赏
  • 举报
回复
网上很多方法都试过了,还是没有解决。。
我的代码是:
<meta content="text/html; charset=gb2312" http-equiv="Content-Type">

Response.Clear()
Response.ContentType = "application/vnd.ms-excel"
请哪位大侠指导下。。。
yan11cn 2010-01-20
  • 打赏
  • 举报
回复
HTML、数据库读取、ASP输出这3个编码得统一
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<% Response.CodePage=936%>
<% Response.Charset="gb2312" %>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
红色@这句必须在第一行 如果原来有@语句 那就删掉 换上面的
  • 打赏
  • 举报
回复
为什么不先google
http://www.google.cn/search?hl=zh-CN&client=aff-seb&source=hp&hs=0Wn&newwindow=1&q=asp+excel%E5%AF%BC%E5%87%BA+%E4%B9%B1%E7%A0%81&aq=1&oq=
尝试别人提供的方法呢?
这样你还能有一个自己学习的过程,乱码这种问题一般就在于编码的事造成的
motefancysilver 2010-01-20
  • 打赏
  • 举报
回复
求助....
qq8568690 2010-01-20
  • 打赏
  • 举报
回复
我昨天也遇到过这个问题,在插入access时变成乱码 网上的例子基本都试过了还是乱码
解决的办法就是把DW里面首参选参数那里 改成简体gb2312就OK了 插入正常,打印出来也正常。
motefancysilver 2010-01-19
  • 打赏
  • 举报
回复
用了上面的方法,还是不管
lzp4881 2010-01-19
  • 打赏
  • 举报
回复
页面加上
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<%
Session.CodePage=936
Response.Charset="gb2312"
%>

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧