asp+sql写入EXCEL当中,三个问题:显示中文和所有出现表格边框以及直接打开EXCEL显示数据!(另外50分指定地方给付)

kw123 2007-12-15 04:42:18
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="include/conn.asp"-->
<%
Response.Buffer=TRUE
Response.AddHeader "Content-Disposition ","attachment; filename=查询报表 "&replace(now(), ": ", "- ")& ".xls "
Response.contentType= "application/vnd.ms-excel"
dim sql,rs
sql= "select * from pro_info "
set rs=conn.execute(sql)
%>
<table width= "437 " border= "1" align= "center " cellpadding= "0 " cellspacing= "1 " id= "data " >
<td width= "56 " >编号</td >
<td width= "91 " >名称</td >
<td width= "108 " >快捷号</td >
<td width= "85 " >规格</td >
</tr >
<%
if rs.eof or rs.bof then
else
do while not rs.eof
%>
<td> <%=rs("pinID")%> </td>
<td> <%=trim(rs( "name"))%> </td>
<td> <%=trim(rs( "kuai"))%> </td>
<td> <%=trim(rs( "gui"))%> </td>
</tr>
<%
rs.movenext
loop
%>
</table>
<%
end if
set rs=nothing
set conn=nothing
%>


显示导入成功!
但是存储的中文为乱码显示,如何解决?
边框为所显示的数据,其他为空白,能否全部为边框显示?(就跟我门打开EXCEL时候一样)
能单击按纽提示是否导入到EXCEL中,然后直接打开EXCEL并数据显示?

共100分,另外地方:
http://topic.csdn.net/u/20071213/13/04e8f25e-a57a-4d98-9034-49273d1f2316.html
给50分
...全文
257 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
fcuandy 2007-12-17
  • 打赏
  • 举报
回复
还有两个问题:如果打开连接直接打开EXCEL并且将文件导入进去.不用出现另存和打开啊?

还有两个问题:如打开连接直接打开EXCEL并且将文件导入进去.不用出现另存和打开啊?

你指的是直接把sql数据存到excel里?

如果是这个意思,请参见.

http://topic.csdn.net/u/20071103/15/d42b9c9a-fad8-4ced-8d2d-a025ac58f1a1.html
kw123 2007-12-17
  • 打赏
  • 举报
回复
TeEvil 的方法没有该语句的方式


fcuandy :的方式解决了乱码的问题! 已经获得50分

还有两个问题:如果打开连接直接打开EXCEL并且将文件导入进去.不用出现另存和打开啊?

另外边框的问题!

在线等待!

另外开贴100分!


kw123 2007-12-17
  • 打赏
  • 举报
回复
有没有把三个问题都解决掉的?

如果有,再开贴100分的!

谢谢大家
pzhuyy 2007-12-16
  • 打赏
  • 举报
回复
除表格以外其它的空白方法,没测试..楼主可以试一下.

<!-- #include file= "adminconn.asp " -- >
<object id=Spreadsheet1 classid=clsid:0002E510-0000-0000-C000-000000000046 style= "width:100%;height:100% " > </object >
<script language=vbscript >
Sub Window_OnLoad()

Dim chConstants

Spreadsheet1.ActiveSheet.Cells.Clear

Spreadsheet1.ActiveSheet.cells(1, 1).Value = "定单号 "
Spreadsheet1.ActiveSheet.Cells(1, 2).Value = "准考证号 "
Spreadsheet1.ActiveSheet.Cells(1, 3).Value = "姓名 "
Spreadsheet1.ActiveSheet.Cells(1, 4).Value = "金额 "
Spreadsheet1.ActiveSheet.Cells(1, 5).Value = "报名时间 "
Spreadsheet1.ActiveSheet.Cells(1, 6).Value = "成功与否 "
Spreadsheet1.ActiveSheet.Cells(1, 7).Value = "银行类型 "
Spreadsheet1.ActiveSheet.Cells(1, 8).Value = "专业 "
Spreadsheet1.ActiveSheet.Cells(1, 9).Value = "科目 "
Spreadsheet1.ActiveSheet.Cells(1, 10).Value = "考试时间 "

<%set numrs=server.createobject( "ADODB.recordset ")
numsql= "select billno,testno,name,amount,succeed,type,subjectname,sj,billdate,amount,mc from xxdd where testno= '052501200002 ' and billno is not null group by testno,billno,amount,billdate,succeed,type,mc,name,subjectname,amount,sj "
numrs.open numsql,conn,3,3
i=2
do while not numrs.eof
b=cstr(numrs( "testno "))% >
Spreadsheet1.ActiveSheet.Cells( <%=i% >, 1).Value = <%=numrs( "billno ")% >

Spreadsheet1.ActiveSheet.Cells( <%=i% >, 2).value= " <%=numrs( "testno ")% > "

Spreadsheet1.ActiveSheet.Cells( <%=i% >, 3).Value = " <%=numrs( "name ")% > "
Spreadsheet1.ActiveSheet.Cells( <%=i% >, 4).Value = <%=numrs( "amount ")% >
Spreadsheet1.ActiveSheet.Cells( <%=i% >, 5).Value = <%=numrs( "billdate ")% >
Spreadsheet1.ActiveSheet.Cells( <%=i% >, 6).Value = " <%=numrs( "succeed ")% > "
Spreadsheet1.ActiveSheet.Cells( <%=i% >, 7).Value = " <%=numrs( "type ")% > "
Spreadsheet1.ActiveSheet.Cells( <%=i% >, 8).Value = " <%=numrs( "mc ")% > "
Spreadsheet1.ActiveSheet.Cells( <%=i% >, 9).Value = " <%=numrs( "subjectname ")% > "
Spreadsheet1.ActiveSheet.Cells( <%=i% >, 10).Value = " <%=numrs( "sj ")% > "

Spreadsheet1.ActiveSheet.Cells( <%=i% >, 11).Value = "0 "


<%i=i+1
numrs.movenext
loop
numrs.close()% >

End Sub
</script >
pzhuyy 2007-12-16
  • 打赏
  • 举报
回复
先测试一下生成表格的时候是否有乱码,如果没有乱码再另存为excel.
kw123 2007-12-16
  • 打赏
  • 举报
回复
我就是通过那个改动的,但是存在我说的问题啊?我看看!行的话,赶紧结帖
kw123 2007-12-15
  • 打赏
  • 举报
回复
还有的问题
TeEvil 2007-12-15
  • 打赏
  • 举报
回复
response.setContentType("application/vnd.ms-excel")
楼主试哈,应该没有问题的。
fcuandy 2007-12-15
  • 打赏
  • 举报
回复
去掉下面两句,看在网页上显示时是否有乱码.

Response.AddHeader "Content-Disposition ","attachment; filename=查询报表 "&replace(now(), ": ", "- ")& ".xls "
Response.contentType= "application/vnd.ms-excel"

如果还有,那可能就是数据库中存储的编码格式与文档声明格式不同.

try
修改第一句为
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
然后,打开记事本,将此asp文件另存,保存时选择编码方式为utf-8,再覆盖原来的文件.

看看这样会不会有乱码.

28,390

社区成员

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

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