如何从经典 ASP 输出 Excel *.xls 文件 [英] How to output an Excel *.xls file from classic ASP

查看:37
本文介绍了如何从经典 ASP 输出 Excel *.xls 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有许多生成的 html 表格,我需要将它们输出为 Excel 文件.该网站是用经典的 ASP 编码的.这可能吗?可以通过某种方式使用 Open Office 库来完成吗?

I have a number of generated html tables that I need to output as an Excel file. The site is codded in classic ASP. Is this possible? Could it be done by somehow using the Open Office libraries?

到目前为止,我已经尝试了一些建议,但似乎失败了.理想情况下,我希望用户能够单击将开始下载 .xls 文件的链接.这段代码:

Thus far, I have tried some of the suggestions, but it seems to fail. Ideally, I want the user to be able to click a link that will begin the download of a .xls file. This code:

<%@ Language=VBScript %>
<%  option explicit

Response.ContentType = "application/vnd.ms-excel"
Response.AppendHeader "content-disposition", " filename=excelTest.xls"
%>
<table>
    <tr>
        <th>Test Col 1</th>
        <th>Test Col 2</th>
        <th>Test Col 3</th>
        <th colspan="2">Test Col 4</th>
        <th>Test Col 6</th>
        <th>Test Col 7</th>
    </tr>
    <tr>
        <td>Data</td>
        <td>Data</td>
        <td>Data</td>
        <td>Data</td>
        <td>Data</td>
        <td>Data</td>
        <td>Data</td>
    </tr>
</table>

使用IE7获取页面时似乎失败.IE 说它无法下载 excelTest.asp"并且请求的站点不可用或无法找到."

seems to fail when IE7 is used to get the page. IE says that it "cannot download excelTest.asp" and that "The requested site is either unavailable or cannot be found."

推荐答案

是 AddHeader,而不是 AppendHeader.

It's AddHeader, not AppendHeader.

<%@ Language=VBScript %>
<%  Option Explicit

Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "attachment; filename=excelTest.xls"
%>
<table>
    <tr>
        <td>Test</td>
    </tr>
</table>

更新:我写了一篇关于如何在 ASP Classic 中生成 Excel 文件.它包含一段相当有用的代码来生成 xls 和 csv 文件.

Update: I've written a blog post about how to generate Excel files in ASP Classic. It contains a rather useful piece of code to generate both xls and csv files.

这篇关于如何从经典 ASP 输出 Excel *.xls 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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