将数据导出到Excel [英] export data to Excel

查看:95
本文介绍了将数据导出到Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨专家,


我从数据库中检索数据并在ASP上显示,然后我将这些

数据导出到一个文件,如Excel(最好的)或文本文件。可能吗?我认为

这是可能的,但我怎么能这样做?感谢您的帮助。


Atse

Hi experts,

I retrieve data from the database and display on ASP, then I export these
data to a file, like Excel (the best) or text file. Is it possible? I think
it is possible, but how can I do that? Thanks for any help.

Atse

推荐答案

您可以做几件事。


1.在表格中构建数据并将其添加到页面顶部:

<%Response.ContentType =" application / vnd。 MS-Excel的" %>

2.自己构建一个逗号分隔的字符串并将字符串保存到文件

,并带有.csv文件并链接到它。


3.使用Office Web Components:
http://office.microsoft.com/downloads/2002/owc10.aspx 。在你去那个

路线之前,请先阅读此处。 http://support.microsoft.com/?id=317316


如果您需要更多关于1或2的详细信息,请回复一下您的数据样本

查询,什么不是。


雷在家

" atse" <杜****** @ yahoo.com>在消息中写道

新闻:7V ********************** @ news01.bloor.is.net。 cable.rogers.com ...
There are a couple of things you can do.

1. Build your data in a table and add this to the top of your page:
<% Response.ContentType = "application/vnd.ms-excel" %>
2. Build yourself a comma delimited string and save the string to a file
with a .csv file and link to it.

3. Use Office Web Components:
http://office.microsoft.com/downloads/2002/owc10.aspx. Before you''d go that
route, read here though. http://support.microsoft.com/?id=317316

If you need more details on 1 or 2, post back with a sample of your data
querying and what not.

Ray at home
"atse" <du******@yahoo.com> wrote in message
news:7V**********************@news01.bloor.is.net. cable.rogers.com...
嗨专家,

我从数据库中检索数据并在ASP上显示,然后我将这些数据导出到一个文件,像Excel(最好的)或文本文件。可能吗?我认为这是可能的,但我怎么能这样做?感谢您的帮助。

Atse
Hi experts,

I retrieve data from the database and display on ASP, then I export these
data to a file, like Excel (the best) or text file. Is it possible? I think it is possible, but how can I do that? Thanks for any help.

Atse



谢谢Ray。我记得你之前给了我很大的帮助。是的,我真的想要导出一个csv文件。

我有大的csv文件包含客户的联系信息。我想通过邮政编码导出

,并输入相应的csv文件。什么是最简单的方式

这样做?再次感谢。


Atse

" Ray at<%= sLocation%>" < myfirstname at lane 34。 KOMM>在留言中写道

新闻:O6 ************** @ TK2MSFTNGP11.phx.gbl ...
Thanks Ray. I remember you have given me great helps before. Yes, I really
want to export a csv file.
I have big csv files containing customers'' contact info. I want to export
them by zip code and type to respective csv files. What is the simplest way
to do that? Thanks again.

Atse
"Ray at <%=sLocation%>" <myfirstname at lane 34 . komm> wrote in message
news:O6**************@TK2MSFTNGP11.phx.gbl...
有几个您可以做的事情。

1.在表格中构建数据并将其添加到页面顶部:
<%Response.ContentType =" application / vnd.ms-的excel" %>

2.为自己构建一个逗号分隔的字符串,并将字符串保存到一个带有.csv文件的文件并链接到它。

3。使用Office Web Components:
http://office.microsoft .COM /下载/ 2002 / owc10.aspx 。在你去
之前,请阅读此处。 http://support.microsoft.com/?id=317316

如果您需要更多关于1或2的详细信息,请回复一下您的数据样本
查询什么不是。

雷在家

atse <杜****** @ yahoo.com>在消息中写道
新闻:7V ********************** @ news01.bloor.is.net。 cable.rogers.com ...
There are a couple of things you can do.

1. Build your data in a table and add this to the top of your page:
<% Response.ContentType = "application/vnd.ms-excel" %>
2. Build yourself a comma delimited string and save the string to a file
with a .csv file and link to it.

3. Use Office Web Components:
http://office.microsoft.com/downloads/2002/owc10.aspx. Before you''d go that route, read here though. http://support.microsoft.com/?id=317316

If you need more details on 1 or 2, post back with a sample of your data
querying and what not.

Ray at home
"atse" <du******@yahoo.com> wrote in message
news:7V**********************@news01.bloor.is.net. cable.rogers.com...
嗨专家,

我从数据库中检索数据并在ASP上显示,然后我将
这些数据导出到一个文件,像Excel(最好的)或文本文件。可能吗?我
Hi experts,

I retrieve data from the database and display on ASP, then I export these data to a file, like Excel (the best) or text file. Is it possible? I


认为

这是可能的,但我怎么能这样做?感谢您的帮助。

Atse
it is possible, but how can I do that? Thanks for any help.

Atse




我会假装你有这样的数据:


CustID名字姓氏地址城市状态ZIP

1 Bo Brady 1街道某处XX 10001

2希望Brady 1 Street Somewhere XX 10001

3 Jack Deveraux 2 Road Somewhere XX 10002

4 Jennifer Deveraux 2 Road Somewhere XX 10002

5 Abe Carver 3大道某处XX 10003

6 Lexie Carver 3 Ave.某处XX 10003

7 Tony Dimera 4 Lane某处XX 10004

8 Rex Dimera 5 Way Somewhere XX 10005

9 Cassie Dimera 4 Lane Somewhere XX 10004

10 Greta Von Amberg 6沼泽某地XX 10006


所以,就像,你想要一堆文件,如:

10001.csv,10002.csv等?也许是这样的:


< object runat =" server" progid =" Scripting.FileSystemObject"

id =" oFSO">< / object>

<%


昏暗的oADO,oRS

昏暗的输出

昏暗的aZIPs,我,sZIP


Const OUTPUT_PATH =" D:\\ \\ path \"

sSQL =" SELECT DISTINCT(ZIP)FROM Customers"

设置oADO = Server.CreateObject(" ADODB.Connection")

oADO.Open YourConnectionString

设置oRS = oADO.Execute(sSQL)

aZIPs = oRS.GetRows()

oRS.Close:设置oRS = Nothing


For i = 0 To UBound(aZIPs,2)

sZIP = aZIPs(0,i)

sSQL =" SELECT CustID,Firstname,Lastname,Address,City,State,ZIP FROM

Customers WHERE ZIP =''" &安培; sZIP& "''"

设置oRS = oADO.Execute(sSQL)

sOutput = oRS.GetString(,,",",vbCrLf)
oRS.Close:设置oRS = Nothing

oFSO.CreateTextFile(OUTPUT_PATH& sZIP&" .csv",True)。写sOutput

Response.Write"< a href =""" &安培; sZIP& " .csv"">点击此处下载CSV

,邮政编码为 &安培; sZIP& "< / a>< br>"

下一页


oADO.Close:设置oADO = Nothing

%>


我们要做的就是获取所有拉链,然后遍历所有拉链,查询所有

每个拉链的数据,以及从每个结果集中写一个CSV。


Ray在家里


" atse" <杜****** @ yahoo.com>在消息中写道

news:n8 ********************* @ news01.bloor.is.net.c able.rogers.com ...
I will pretend that you have data as such:

CustID Firstname Lastname Address City State ZIP
1 Bo Brady 1 Street Somewhere XX 10001
2 Hope Brady 1 Street Somewhere XX 10001
3 Jack Deveraux 2 Road Somewhere XX 10002
4 Jennifer Deveraux 2 Road Somewhere XX 10002
5 Abe Carver 3 Ave. Somewhere XX 10003
6 Lexie Carver 3 Ave. Somewhere XX 10003
7 Tony Dimera 4 Lane Somewhere XX 10004
8 Rex Dimera 5 Way Somewhere XX 10005
9 Cassie Dimera 4 Lane Somewhere XX 10004
10 Greta Von Amberg 6 Swamp Somewhere XX 10006


So, like, you want a bunch of files like:
10001.csv, 10002.csv, etc.? Maybe something like this:

<object runat="server" progid="Scripting.FileSystemObject"
id="oFSO"></object>
<%

Dim oADO, oRS
Dim sOutput
Dim aZIPs, i, sZIP

Const OUTPUT_PATH = "D:\Path\"
sSQL = "SELECT DISTINCT(ZIP) FROM Customers"
Set oADO = Server.CreateObject("ADODB.Connection")
oADO.Open YourConnectionString
Set oRS = oADO.Execute(sSQL)
aZIPs = oRS.GetRows()
oRS.Close : Set oRS = Nothing

For i = 0 To UBound(aZIPs, 2)
sZIP = aZIPs(0, i)
sSQL = "SELECT CustID,Firstname,Lastname,Address,City,State,ZIP FROM
Customers WHERE ZIP=''" & sZIP & "''"
Set oRS = oADO.Execute(sSQL)
sOutput = oRS.GetString(,,",",vbCrLf)
oRS.Close : Set oRS = Nothing
oFSO.CreateTextFile(OUTPUT_PATH & sZIP & ".csv", True).Write sOutput
Response.Write "<a href=""" & sZIP & ".csv"">Click here to download CSV
for ZIP code " & sZIP & "</a><br>"
Next

oADO.Close : Set oADO = Nothing
%>

What that''ll do is get all the zips, then loop through them all, query all
the data for each zip, and write a CSV from each resultset.

Ray at home

"atse" <du******@yahoo.com> wrote in message
news:n8*********************@news01.bloor.is.net.c able.rogers.com...
谢谢雷。我记得你之前给了我很大的帮助。是的,我真的想要导出一个csv文件。
我有大的csv文件包含客户的联系信息。我想通过邮政编码导出它们并输入相应的csv文件。什么是最简单的
方式呢?再次感谢。

Atse

" Ray at<%= sLocation%>" < myfirstname at lane 34。 KOMM>在消息中写道
新闻:O6 ************** @ TK2MSFTNGP11.phx.gbl ...
Thanks Ray. I remember you have given me great helps before. Yes, I really
want to export a csv file.
I have big csv files containing customers'' contact info. I want to export
them by zip code and type to respective csv files. What is the simplest way to do that? Thanks again.

Atse
"Ray at <%=sLocation%>" <myfirstname at lane 34 . komm> wrote in message
news:O6**************@TK2MSFTNGP11.phx.gbl...
你可以做几件事。

1.在表格中构建数据并将其添加到页面顶部:
<%Response.ContentType =" application / vnd.ms-excel" %>

2.构建一个以逗号分隔的字符串并将字符串保存到
文件
There are a couple of things you can do.

1. Build your data in a table and add this to the top of your page:
<% Response.ContentType = "application/vnd.ms-excel" %>
2. Build yourself a comma delimited string and save the string to a file
with .csv 3.使用Office Web Components:
http://office.microsoft.com/downloads/2002/owc10.aspx 。在您去
with a .csv file and link to it.

3. Use Office Web Components:
http://office.microsoft.com/downloads/2002/owc10.aspx. Before you''d go


路线之前,请先阅读此处。 http://support.microsoft.com/?id=317316

如果您需要更多关于1或2的详细信息,请回复一下您的数据样本
查询什么不是。

雷在家

atse <杜****** @ yahoo.com>在消息中写道
新闻:7V ********************** @ news01.bloor.is.net。 cable.rogers.com ...
route, read here though. http://support.microsoft.com/?id=317316

If you need more details on 1 or 2, post back with a sample of your data
querying and what not.

Ray at home
"atse" <du******@yahoo.com> wrote in message
news:7V**********************@news01.bloor.is.net. cable.rogers.com...
嗨专家,

我从数据库中检索数据并在ASP上显示,然后我导出
Hi experts,

I retrieve data from the database and display on ASP, then I export


这些数据到文件,如Excel(最好的)或文本文件。可能吗?我


these data to a file, like Excel (the best) or text file. Is it possible? I


认为

这是可能的,但我怎么能这样做?感谢您的帮助。

Atse
it is possible, but how can I do that? Thanks for any help.

Atse





这篇关于将数据导出到Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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