一般查询的结果,ASP是否可以将查询结果导出至EXCEL文件~ 并下载~(急)

DeliverGuy 2004-02-02 12:03:47
ASP查询出的结果,是不是可以生成EXCEL文件并下载,后台数据库为SQL-2000
如何实现这样的功能?

请求帮助~!
...全文
48 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
mikespook 2004-02-02
  • 打赏
  • 举报
回复
将结果输出为EXCEL能处理的XML格式
twsky 2004-02-02
  • 打赏
  • 举报
回复
<%@ LANGUAGE="VBSCRIPT" %>

Make the object, and set the object to an Excelsheet

Dim MyExcelChart
Set MyExcelChart = CreateObject("Excel.Sheet")

Now lets write the rest of the script, see the comments

' show or dont show excel to user, TRUE or FALSE
MyExcelChart.Application.Visible = True

' populate the cells
MyExcelChart.ActiveSheet.Range("B2:k2").Value = Array
("Week1", "Week2", "Week3", "Week4", "Week5", "Week6", "Week7", "Week8", "Week9", "Week10")
MyExcelChart.ActiveSheet.Range("B3:k3").Value = Array
("67", "87", "5", "9", "7", "45", "45", "54", "54", "10")
MyExcelChart.ActiveSheet.Range("B4:k4").Value = Array
("10", "10", "8", "27", "33", "37", "50", "54", "10", "10")
MyExcelChart.ActiveSheet.Range("B5:k5").Value = Array
("23", "3", "86", "64", "60", "18", "5", "1", "36", "80")
MyExcelChart.ActiveSheet.Cells(3,1).Value="Internet Explorer"
MyExcelChart.ActiveSheet.Cells(4,1).Value="Netscape"
MyExcelChart.ActiveSheet.Cells(5,1).Value="Other"

' Select the contents that need to be in the chart
MyExcelChart.ActiveSheet.Range("b2:k5").Select

' Add the chart
MyExcelChart.Charts.Add
' Format the chart, set type of chart, shape of the bars, show title, get the data for the chart, show
datatable, show legend
MyExcelChart.activechart.ChartType = 97
MyExcelChart.activechart.BarShape =3
MyExcelChart.activechart.HasTitle = True
MyExcelChart.activechart.ChartTitle.Text = "Visitors log for each week shown in browsers percentage"
MyExcelChart.activechart.SetSourceData MyExcelChart.Sheets("Sheet1").Range("A1:k5"),1
MyExcelChart.activechart.Location 1
MyExcelChart.activechart.HasDataTable = True
MyExcelChart.activechart.DataTable.ShowLegendKey = True

' Save the the excelsheet to excelface
MyExcelChart.SaveAs "c:\chart.xls"
%>

Now lets complete the HTML tags.

<HTML>
<HEAD>
<TITLE>MyExcelChart</TITLE>
</HEAD>
<BODY>
</BODY>
</HTML>

This completes yer ASP page, look below for the complete code of myexcelchart.asp

<%@ LANGUAGE="VBSCRIPT" %>
<%
' Create Object
Set MyExcelChart = CreateObject("Excel.Sheet")

' show or dont show excel to user, TRUE or FALSE
MyExcelChart.Application.Visible = True

' populate the cells
MyExcelChart.ActiveSheet.Range("B2:k2").Value = Array
("Week1", "Week2", "Week3", "Week4", "Week5", "Week6", "Week7", "Week8", "Week9", "Week10")
MyExcelChart.ActiveSheet.Range("B3:k3").Value = Array
("67", "87", "5", "9", "7", "45", "45", "54", "54", "10")
MyExcelChart.ActiveSheet.Range("B4:k4").Value = Array
("10", "10", "8", "27", "33", "37", "50", "54", "10", "10")
MyExcelChart.ActiveSheet.Range("B5:k5").Value = Array
("23", "3", "86", "64", "60", "18", "5", "1", "36", "80")
MyExcelChart.ActiveSheet.Cells(3,1).Value="Internet Explorer"
MyExcelChart.ActiveSheet.Cells(4,1).Value="Netscape"
MyExcelChart.ActiveSheet.Cells(5,1).Value="Other"

' Select the contents that need to be in the chart
MyExcelChart.ActiveSheet.Range("b2:k5").Select

' Add the chart
MyExcelChart.Charts.Add
' Format the chart, set type of chart, shape of the bars, show title, get the data for the chart, show
datatable, show legend
MyExcelChart.activechart.ChartType = 97
MyExcelChart.activechart.BarShape =3
MyExcelChart.activechart.HasTitle = True
MyExcelChart.activechart.ChartTitle.Text = "Visitors log for each week shown in browsers percentage"
MyExcelChart.activechart.SetSourceData MyExcelChart.Sheets("Sheet1").Range("A1:k5"),1
MyExcelChart.activechart.Location 1
MyExcelChart.activechart.HasDataTable = True
MyExcelChart.activechart.DataTable.ShowLegendKey = True


' Save the the excelsheet to chart.xls
MyExcelChart.SaveAs "c:\chart.xls"


%>
<HTML>
<HEAD>
<TITLE>MyExcelChart</TITLE>
</HEAD>
<BODY>
</BODY>
</HTML>


DeliverGuy 2004-02-02
  • 打赏
  • 举报
回复
我是想通过一个按钮的功能, <input type=button name="excel" ...>来实现生成当前查询结果为EXCEL文件~!

请求参考资料或参考代码~ 谢谢

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧