出口数据从传统的ASP失败excel文件 [英] Export data to excel file from Classic ASP failing

查看:91
本文介绍了出口数据从传统的ASP失败excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图设置导出到Excel的纪录,但它似乎没有保持在生产服务器上。但是,它似乎工作,我的开发工作站上就好了。我不知道我适合的服务器相关的问题,但我可以使用完全相同的code,以及类似code同样建立了以出口就好了其他应用程序。

I'm trying to export a record set into Excel but it seems to keep failing on the production servers. However, it seems to work just fine on my development workstation. I'm wondering i fit's a server related issue but I have other apps that can export just fine using the same exact code, well similar code same set up.

<%@ Language=VBScript %>
<%Response.expires = -1%>
<%response.buffer = true%>
<%
     Dim today 
     today = "_" + Replace(Date,"/","") + "_" + Replace(Time(),":", "")

     Response.Charset = "ANSI"
     Response.ContentType = "application/octet-stream"
     Response.ContentType = "application/vnd.ms-excel"
     Response.AddHeader "Content-Disposition", "attachment; filename=List" + today + ".xls" 
     Response.ContentType = "application/download"

     set Cnn = server.CreateObject("ADODB.connection")
     Cnn.ConnectionString = Application("Cnn_ConnectionString")
     Cnn.open      

     set rs1 = server.CreateObject("ADODB.Recordset") 
     SQLCollections = "Sp_MysProc @Param1=" & Session("var1")
     rs1.open SQLCollections,cnn
%>
<html>
    <body>
        <table>
            <tr>
                <td>Number</td> 
                <td>Name</td> 
            </tr>
        <%if not rs.eof then
            do while not rs.eof %>
            <tr> 
                <td><%=rs("Number") %></td> 
                <td><%=rs("Name") %></td>	
            </tr>
        <%
            rs.MoveNext
            Loop
           rs.Close
           set rs = Nothing 
         End if        
        %>
        </table>
    </body>
</html>

此外,这个工程从我的机器。但是,当我从生产做它给了我以下消息:

Again, this works from my machine. But when I do it from production it gives me the following message:

Internet Explorer无法下载
  从www.mydomain.com

Internet Explorer cannot download MyFile.asp from www.mydomain.com

的Internet Explorer无法打开
  本网站。请求的网站
  不可用或不能
  找到。请稍后再试。

Internet Explorer was not able to open this Internet site. The requested site is either unavailable or cannot be found. Please try again later.

除了错误有没有办法让它的出口,而不是用一个白色的背景,没有线,即像一个真正的Excel文件会显示为HTML?

Beyond the error is there any way to make it export and not display as HTML with a white background and no lines, i.e. like a real Excel file would?

修改
根据安东尼的回答内容类型已得到纠正。

Edit: Content types have been corrected based on Anthony's answer.

日期是不难codeD,允许多个文件与任何用户的干预(用户请求)。

The date is not hard coded to allow multiple files to be created daily with out any user intervention (user requested).

我已经更新,删除IF NOT EOF。我已经注意到了很多长时间运行的连接,也许有一些这类围绕应用问题。谢谢你的提示。此外,它仍然有效desipte那里是没有记录这是按要求。

I've updated to remove the If Not EOF. I've been noticing a lot of long running connections, perhaps there are a number of these types of issues around the app. Thanks for the tip. Also it still works desipte there being no recordset which was as requested.

编辑2
我已经固定在EOF问题与不正确的列名(哎呀!),它现在可以正确下载从生产我的电脑上。我有Office 2007.但是,事情仍然不会下载至少有一台其他计算机。另一台电脑了Office 2000就可以了。但removeing​​头,并允许它溢出仅仅指刚它适用于所有机器的HTML。

Edit 2 I've fixed on eof the issue with an improper column name (oops!) and it now downloads correctly on my computer from production. I have Office 2007. But the thing still will not download on at least one other computer. This other computer has Office 2000 on it. But removeing the headers and allowing it to spill out jsut the HTML it works on all machines.

可能的Office 2000有一个问题有这样的事情?

Might Office 2000 have an issue with this sort of thing?

推荐答案

首先几个看家的东西。

有少点设置Content-Type的3倍。只要坚持以'应用程序\\ vnd.ms-EXCEL之一。

There is little point setting the Content-Type 3 times. Just stick with the `application\vnd.ms-excel" one.

而不是使用ANSI作为字符集的Windows 1252。

Rather than using "ANSI" as the character set use "Windows-1252".

多大的输出?既然你是缓冲你可能会击中ASP缓冲默认最大IIS6的4MB的。

How big is the output? Since you are buffering you may be hitting the ASP buffer default maximum of 4MB of IIS6.

请关闭缓冲或弹出到元数据库编辑器,并增加对应用程序的AspBufferingLimit的价值。

Either turn off buffering or pop into metabase editor and increase the AspBufferingLimit value on your application.

修改

接下来的事情我会尝试是我的客户机上安装提琴手并尝试下载。你怎么在小提琴手看到当你试图下载该文件?

The next thing I would try is install Fiddler on my client and attempt the download. What do you see in fiddler when you attempt to download the file?

您已经安装了什么版本的MS Office?

What version of MS office do you have installed?

这篇关于出口数据从传统的ASP失败excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆