asp Excel导出格式错误问题
程序代码:
<html> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <style> p h3{font-family: "宋体"; font-weight:bold ; font-size:13px;} table th { Height: 35px; font-family: "宋体"; font-weight:bold ; font-size:13px; } table td { Height: 25px; font-family: "宋体"; font-size:13px; } </style> <%Response.expires = -1%> <%Response.Buffer = true%> <% Dim s, sql, filename, fs, myfile, x, act, stime act = request("act") sgrade = Trim(request("sgrade"))'接收隐藏域传来的参数 sclass = Trim(request("sclass"))'接收隐藏域传来的参数 society = Trim(request("society"))'接收隐藏域传来的参数 file_name = sgrade&sclass&society If file_name = "" Then file_name = "村居导出" End If sql = "select top 1 * from gdn order by id desc " Set rs = conn.Execute(sql) kxj = rs(2) '取得开学时间 Response.AddHeader "Content-Disposition", "attachment; filename=" + file_name + ".xls" Response.ContentType = "application/vnd.ms-excel" %> <body> <h3 align="center">农村留守儿童交接名单 (<% =file_name %>) </h3> <table width="850" height="292" border="1" align="center" > <tr style="font-weight:bold;" > <td colspan="7" rowspan="2" align="center" valign="middle">学生情况</td> <td colspan="7" align="center" valign="middle">监护情况</td> <td rowspan="3" align="center" valign="middle">联系电话</td> </tr> <tr style="font-weight:bold;" > <td colspan="3" align="center" valign="middle">实际监护人</td> <td colspan="4" align="center" valign="middle">法定监护人</td> </tr> <tr style="font-weight:bold;" > <td align="center" valign="middle">序号</td> <td align="center" valign="middle">姓名</td> <td align="center" valign="middle">性别</td> <td align="center" valign="middle">出生年月</td> <td align="center" valign="middle">地址</td> <td align="center" valign="middle">就读班级</td> <td align="center" valign="middle">班主任<br>姓名</td> <td align="center" valign="middle">班主任<br>联系电话</td> <td align="center" valign="middle">姓名</td> <td align="center" valign="middle">与该生<br>关系</td> <td align="center" valign="middle">联系电话</td> <td align="center" valign="middle">姓名</td> <td align="center" valign="middle">与该生<br>关系</td> <td align="center" valign="middle">务工地点</td> </tr> <% Dim num num = 1 strSql = request.Form("strSql") '接收隐藏域传来的参数 Set rstData = conn.Execute(strSql) If Not rstData.EOF And Not rstData.BOF Then While Not rstData.EOF %> <tr> <td align="center" valign="middle"><% =num %></td> <td align="center" valign="middle"><%=rstData("sname")%></td> <td align="center" valign="middle"><%=rstData("sex")%></td> <td align="center" valign="middle"><%=rstData("birth")%></td> <td align="center" valign="middle"><% If InStr(rstData("address"), "重庆市") Then response.Write Replace(rstData("address"), "重庆市", "") ElseIf InStr(rstData("address"), "") Then response.Write Replace(rstData("address"), "", "") Else response.Write rstData("address") End If %></td> <td align="center" valign="middle"><%=rstData("sgrade")%><%=rstData("sclass")%></td> <td align="center" valign="middle"><%=rstData("teachername")%></td> <td align="center" valign="middle"><%=rstData("teachertel")%></td> <td align="center" valign="middle"><%=rstData("sguardian")%></td> <td align="center" valign="middle"><%=rstData("snexus")%></td> <td align="center" valign="middle"><%=rstData("stel")%></td> <td align="center" valign="middle"><%=rstData("fguardian")%></td> <td align="center" valign="middle"><%=rstData("fnexus")%></td> <td align="center" valign="middle"><% = Left(rstData("fjob"), 2) %></td> <td align="center" valign="middle"><%=rstData("ftel")%></td> </tr> <% rstData.movenext num = num + 1 Wend %> </table> <p align="center"> <strong>注:本清单由学校学期初统计录入,一式两份,村(居)委员会、学校各存一份。</strong></p> <p align="center"> </p> <p align="center"> </p> </body> </html> <% End If rstData.Close Set rstData = Nothing Conn.Close Set Conn = Nothing %>
能导出,虽然报错,但也能打开。但这报格式错误来怎么解决?
Response.AddHeader "Content-Disposition", "attachment; filename=" + file_name + ".xls" Response.ContentType = "application/vnd.ms-excel"
有问题?求解。
[此贴子已经被作者于2020-7-16 11:00编辑过]