如何下载到 Excel?

发布于 2024-10-09 01:44:17 字数 227 浏览 0 评论 0原文

我想为我的 Coldfusion 网站的不同部分上提供的几组不同的数据提供“下载到 Excel”功能。我正在使用 Coldfusion,并且希望使用免费的自定义标签/库来帮助我完成此任务,而不是自己从头开始编码。我已被指向 cflib.org 但不知道如何开始。有人对下载 Coldfusion 网站数据以实现卓越有任何想法、评论或资源吗?

I'd like to go about offering a "download to excel" functionality for several different sets of data available on different parts of my coldfusion website. I'm using coldfusion and would love to use freely available custom tags / libraries that can help me accomplish this instead of coding it all myself from scratch. I've been pointed to cflib.org but am not sure how to get started. Anyone have any ideas, comments, or resources about downloading coldfusion website data to excel?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

无语# 2024-10-16 01:44:17

我过去在包含大量表格统计数据的 Intranet 中使用的一种方法是利用 Excel 可以读取 HTML 的优势。

在我打算提供 Excel 链接的页面上,我将核心表以 HTML 形式写入文件,并在呈现的页面中包含指向该文件的链接。然后,您可以使用 .xls 扩展名提供此页面,使用元标头,甚至使用带有 CFCONTENT 的中间页面,以便让浏览器启动 Excel 来显示内容。

这种方法可以扩展到每页任意数量的表。您必须编写一个标签来包含该表,然后该标签将负责编写文件并提供其中包含的所有 HTML 内容的下载链接。

抱歉缺少示例代码。如果我对该过程的描述让您摸不着头脑,那么我将为您提供一些示例。

An approach that I have used in the past for an intranet with a load of tabular statistical data is to take advantage of the fact that Excel can read HTML.

On pages that I intend to provide Excel links for, I write out the core table as HTML to a file and include a link to that file in the rendered page. You can then serve this page with an .xls extension, use meta headers or even use an intermediary page with CFCONTENT in order to have your browser fire up Excel to display the content.

This approach can be extended for an arbitrary number of tables per page. You would have to write a tag to contain the table which will then take care of writing the file and supplying the download link for all HTML content contained within.

Sorry for the lack of example code. If my description of the process has left you scratching your head then I'll provide some examples for you.

最初的梦 2024-10-16 01:44:17

您还可以使用 html 表,如:

<cfquery name="data" datasource="whatever">
...
</cfquery>

<cfheader name="Content-Disposition" value="inline; filename=fileName.xls">
<cfcontent type="application/x-msexcel" reset="true">

<table border="0" cellspacing="0" cellpadding="0">
    <thead>
        <tr>
            <td>Col1</td>
            <td>Col2</td>
        </tr>
    </thead>
    <tbody>
        <cfoutput query="data">
            <tr>
                <td>#data.Col1#</td>
                <td>#data.Col2#</td>
            </tr>
        </cfoutput>
    </tbody>
</table>

hth,

larry

You can also use an html table, as in:

<cfquery name="data" datasource="whatever">
...
</cfquery>

<cfheader name="Content-Disposition" value="inline; filename=fileName.xls">
<cfcontent type="application/x-msexcel" reset="true">

<table border="0" cellspacing="0" cellpadding="0">
    <thead>
        <tr>
            <td>Col1</td>
            <td>Col2</td>
        </tr>
    </thead>
    <tbody>
        <cfoutput query="data">
            <tr>
                <td>#data.Col1#</td>
                <td>#data.Col2#</td>
            </tr>
        </cfoutput>
    </tbody>
</table>

hth,

larry

不甘平庸 2024-10-16 01:44:17

基于 @Ciaran Archer 的答案,我通常使用 CSV 来完成此操作,如果安装在客户端的 PC 上,Excel 将从网络上打开该文件。假设您正在使用的数据来自数据库,请使用 QueryToCSV() 来自 Ben Nadel 的网站,如下所示:

<cfquery name="data" datasource="">
...
</cfquery>
<cfinclude template="fun_queryToCSV.cfm">
<cfheader name="Content-Disposition" value="filename=my-file-name.xls">
<cfcontent type="test/csv" reset="true">
<cfoutput>#querytoCSV(data)#</cfoutput>

cfcontent 上的“重置”会清除响应缓冲区,以便其中唯一的内容就是后面的内容。或者,如果您已经将数据作为文件,则 cfcontent 有一个“文件”属性,可以直接提供其内容。

Building on @Ciaran Archer's answer, I usually use CSV to accomplish this, which Excel will open up from the web if installed on a client's PC. Assuming the data you're working with is coming out of a database, use the QueryToCSV() from Ben Nadel's site as such:

<cfquery name="data" datasource="">
...
</cfquery>
<cfinclude template="fun_queryToCSV.cfm">
<cfheader name="Content-Disposition" value="filename=my-file-name.xls">
<cfcontent type="test/csv" reset="true">
<cfoutput>#querytoCSV(data)#</cfoutput>

The "reset" on cfcontent clears the response buffer so that the only thing inside of it is what comes after. Alternately, if you already have the data as file, cfcontent has a "file" attribute that will serve its contents up directly.

无法回应 2024-10-16 01:44:17

最后,我们使用了 cflib 中的 Query2Excel 函数.org,并对其进行了轻微修改以满足我们的特定需求。

In the end, we used the Query2Excel function from cflib.org, and modified it slightly to suit our specific needs.

北城孤痞 2024-10-16 01:44:17

对于使用 Coldfusion 9+ 并且能够使用 cfspreadsheet 的用户,您可以利用 SpreadsheetReadBinary() 使电子表格可下载,而无需先将电子表格写入文件。

For those on Coldfusion 9+ and able to use cfspreadsheet, you can leverage SpreadsheetReadBinary() to make the spreadsheet downloadable without having to write the spreadsheet to a file first.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文