请问如何把页面查询到的记录导入到Excel中呢?

chinadllh 2001-07-16 05:10:31
...全文
194 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
hydnoahark 2001-07-17
  • 打赏
  • 举报
回复
使用ADO可以直接访问Excel文件的
truemichael 2001-07-17
  • 打赏
  • 举报
回复
Creating Excel WorkSheets with ASP
By Wayne Berry
This Issue
In this issue we will discuss and demonstrate how to create Microsoft Excel worksheets from Active Server pages. Though there are many ways that this can be done, we have chosen a method for the example that conserves server load and puts the majority work on the client.
Three Techniques
The other methods however are worth mentioning, since there are many ways to come to the same ends. The ends in this case is having real time data served from the web server and available in Excel upon the clients machine. The three methods are as follows: 1) Creating the VBA component on the web server and either streaming it down to the client or linking to the finished component from a separate page. 2) Making Excel call the web server for the data using HTTP and inserting it into the right areas of the Excel WorkSheet. 3) Creating an HTML stream that Excel can interrupt and translate into a Excel WorkSheet. The third technique is the one that I am going to discuss in this article, but first let take a brief look at the other options.
The First Technique
The first technique is to create a VBA component, in this case an Excel WorkSheet, on the web server and either streaming it down to the browser or linking to it from another page. This technique at first glance seems the most appealing. Since you can create COM object on an ASP page by calling Server.CreateObject with the name of the object that you want to create. Then with multiple calls to method and properties of the object you could fill in the data of the WorkSheet. However, at second glance, this is not the best technique. To start with it would cause considerable server load if the server was receiving multiple requests for these objects. Another problem arises when opening the object. Each object must have a unique file name, objects with shared file names give all by the first instantiation read only permission. This means that for every request to the web server you must generate a unique name for that object. Since you are generating all these files you must also clean up the files, or they will start to consume disk space. The clean up mechanism will have to coordinate with the request, so files are not deleted when they are being used. You can see how the problems start to mount. Another issues is the size of the Excel files that you will be streaming, Excel files for small WorkSheets are usually big in comparison to an HTML page or a graphic. The large size cause network strain and slow response time for sites with minimal bandwidth. The final problem is, VBA objects are not multi-threaded and were never intended to be used as a server. Imagine this, you are a VBA object and you happily live on a machine where your owner sometime opens you up to view a document. This is what your designers intended and this is how you where built. You are very proud that you take up a minimum amount of memory and can run on a 486 machine without problems. Suddenly one day your owner throws you on a server and starts to make you open several requests a second. Even with addition memory and a fast processor you where never tested with multiple open instances and you fail miserable at performing your job. Out of the three techniques this is the most interest, but the least workable.
The Second Technique
The second technique is to have Excel call the web server and use the data to fill in WorkSheet. This technique is actually fairly easy to do in Excel 97. Microsoft has added additional functionality to Excel 97 called embedded HTML. There is also a wizard to give you a hand. The typical user experience would be to open an Excel document, push a button that is embedded in a cell, the web site is called and the data appears in the Excel WorkSheet. Through this method is very useable in my opinion it is not as powerful as the third method.
The Third Technique
The third technique is to create an HTML stream that Excel can interrupt and translate into an Excel WorkSheet. We will spend the remainder of the article describing how this works and how to use it. The only major flaw in this technique is that we can only fill in one Excel WorkSheet at a time, multiple Excel Worksheet in a WorkBook will not work. Before we get started there are a couple of things we need to discuss about Microsoft Internet Explorer and Excel 97.
Internet Explorer 3.0
Internet Explorer 3.0 is capable of displaying an Microsoft Excel Worksheet just as it would be displayed in the Excel application, if Excel is installed. The usual way of displaying the worksheet in the IE browser is to enter the URL of an excel workbook with the extension xls. IE then uses the extension to figure out the mime type and the application the mime type and the extension are associated with. IE needs to determine the mime type from the extension since IIS and other web servers pass the data stream back as a application/octect-stream. IE changes the mime type to application/vnd.ms-excel. If the IIS server returned application/vnd.ms-excel as the mime type, or Content-Type as defined in HTTP, IE would try to interrupt the data stream as an Excel WorkSheet. By interrupt I mean launch Microsoft Excel and display the data within the IE using Excel. So, any application sending back a Content-Type of application/vnd.ms-excel will cause IE to display the data as an Excel WorkSheet.
Excel 97
In theory we know how to make Excel come up in the IE Browser, now all we have to do is pass Excel the correct data stream. This might be the trickiest part and also the easiest with Excel 97. The example that we are about to present will not work with earlier versions of Excel, the examples will only work with Excel 97. Excel 97 contains a special piece of code that will generate an Excel WorkSheet from an HTML table. What this means is that we can pass an HTML table back as the data stream and Excel will interpret the data stream as a WorkSheet. Much easier then generating a data stream that looks like an Excel WorkSheet.
Summary
With Excel 97 and Internet Explorer 3.0 we can create an Excel spreadsheet from an HTML table by changing the response Content-Type to application/vnd.ms-excel and sending back an HTML table as the data stream. Why would we want to do this?
Real Time Data, Anytime
If you create your HTML tables using Active Server pages to dynamically fill in the data, you can produce reports using ADO that reflect the current data in the database. As an example, analysis of page hits. Most Internet companies have page hit reports that are generated and viewable through HTML browsers. By changing the mime type on these reports you can display them as Excel WorkSheets that can later be graphed or manipulated.
Reduced Server Load
If you have a dynamically generated web page that reports page hits, it probably has a total at the bottom. The lazy way to generate a total is to execute another SQL call after the original call to display all the hits. Something like:
SELECT SUM(Page_Hits)
FROM PageTable
WHERE DATEDIFF(day,Page_Date,GetDate()) < 1

I call this the lazy way since it makes another call to the database (SQL Server in this case) and causes extra the SQL Sever load. Especially since the aggregate does a table lock, and the GetDate() and DATEDIFF are expensive.
A second technique is to add the page hits up from the original call that displays all the hits. You can easily do this in an Active Server Page with a little code like this:

<%
Total=0
Do While Not RS.eof
%>
<TR>
&l%TD>
<%=RS("Page_Hits)%>
</TD>
</TR>
<%
Total = Total + RS("Page_Hits)
RS.MoveNext
Loop
%>
<TR>
<TD>
<B><%=Total%></B>
</TD>
</TR>

This technique however has some problems when it comes to more complicated aggregates then SUM. For instance, what if you were trying to calculate the mean, median, and average. With more complicated functions, there is room for development bugs.
There is a third technique when creating Excel WorkSheets. This technique involves embedded Excel formulas within the Excel WorkSheets. These formulas can do calculations like sum and average. This technique has the same advantage as the second technique, namely it doesn't need to go back to the SQL Server for additional queries. Plus, it removes the formula development from the Active Server page developer.

Finally the big advantage is that it removes the complicated formulas from being run on the server and instead, runs them on the client. Since the formulas are not run until the browser loads the data stream in Excel, the server need not do the work of running the formulas as seen in the second technique.

Excel 97
One of the great advantages of displaying your data in Excel is that it is Excel. This means that you get all the advantages of working in Excel, like adding charts, and complicated algorithms in the Excel WorkSheet. Plus, others who are knowledgeable in Excel, such as Sales and Marketing organizations, can save the Excel WorkSheet as an Excel document and manipulate the numbers or graphs to reflect their needs.
Changing the Mime Type
To change the mime type of the response, add the following to the top of your Active Server page.
<%
Response.ContentType = "application/vnd.ms-excel"
%>


An Excel Table with Embedded Formulas
The layout of the Excel WorkSheet will resemble the HTML table that you pass down. The most common mistake is to have HTML, HEAD, TITLE, and BODY tags in your Active Server page. You do not need these tags in your Active Server page. In fact, the WorkSheet will not open correctly with these tags. Here is an example of an Active Server page that will open as an Excel WorkSheet.

<%
Response.ContentType = "application/vnd.ms-excel"
%>
<TABLE>
<TR>
<TD>
<!-- Cell : A1 -->
2
</TD>
</TR>
<TR>
<TD>
<!-- Cell : A2 -->
3
</TD>
</TR>
<TR>
<TD>
<!-- Cell : A3 -->
=SUM(A1:A2)
</TD>
</TR>
</TABLE>


Notice the Excel formula in Cell A3. You can use any supported functions just like SUM is being used here.
Summary
The example above is pretty simple, however it gives you a good idea of what is going on. From here you should be able to use ADO to construct a table based on a results set from your database. Once the table is constructed and passed back to Excel it will appear as an Excel WorkSheet.
chinadllh 2001-07-17
  • 打赏
  • 举报
回复
?
下载代码方式:https://pan.quark.cn/s/957405011bdf 在计算机视觉技术,轮廓提取与心识别被视为两项核心的技术,它们对于图像处理及模式识别领域扮演着不可或缺的角色。本文将深入剖析这两种算法,并围绕"轮廓提取(心识别)算法"这一核心主题,同时结合所提供的压缩包文件"Contour",对相关知识点进行详尽的阐述。 轮廓提取算法,主要功能在于识别并分离图像的不同对象。该算法通过探测物体边缘,构建出明确的边界线,从而实现图像内部各组成部分的区分。在多色位图环境下,不同的色彩可能象征着不同的对象或区域,因此,一个性能优越的轮廓提取算法应当具备处理此类复杂场景的能力。常见的轮廓提取算法包括Canny边缘检测、Sobel算子、Laplacian算子和Hough变换等。这些算法各自具备独特的优缺点,究竟选择何种方法,需要依据具体的应用情境以及性能要求来决定。 1. Canny边缘检测:由John F. Canny所研发,这是一种自适应的多级边缘检测方法。Canny算法借助高斯滤波器来降低噪声干扰,随后运用强度梯度和非极大值抑制技术来定位最显著的边缘,最终通过双阈值检测来区分边缘与噪声。 2. Sobel算子:Sobel算子是一种基于梯度的边缘检测工具,它通过计算图像在水平和垂直方向上的梯度来探测边缘。此方法操作简便且效率较高,但可能对图像的噪声较为敏感。 3. Laplacian算子:Laplacian算子是一种二阶导数算子,能够迅速识别图像的尖峰(即边缘)。然而,它容易受到噪声的影响,因此通常需要与其他技术结合使用,例如Gaussian滤波。 4. Hough变换:Hough变换是一种在参数空间进行边缘检测的方法,它能够检测出任意...
【重要提示】本资源设置为0积分下载,若非0积分请勿轻易下载 亲爱的CSDN用户: 首先感谢你点进这个资源页面。我需要提前说明一个重要情况: **本资源原本已设置为“0积分下载”**,即作者希望完全免费共享。但CSDN平台有时会根据文件的下载热度、文件大小、用户权限等因素,**自动将部分资源的积分调整为非0数值**(如1积分、2积分、5积分等)。这是平台系统的自动行为,而非作者本人的设定。 **因此,如果你当前看到该资源的下载所需积分不是0(例如显示为1、2、3……),请谨慎决定是否下载。** 如果你按照非0积分支付并下载后发现资源内容不符合预期、链接失效,或者实际上该资源本应是免费的,作者无法为此承担积分损失或退还操作。**强烈建议:仅在页面显示为0积分时进行下载。** 另外,本资源描述**并未直接提供具体的下载地址或外部链接**,因为它本身是一个通过CSDN官方上传通道提交的文件/内容包。如果你看到描述没有外部网盘地址,这是正常的——资源文件应通过CSDN内置的“下载”按钮获取。若因平台积分显示异常导致你支付了积分,请优先联系CSDN客服咨询积分退还政策,作者没有权限修改平台自动设定的积分值。 感谢你的理解与支持。技术分享本应开放,但受限于平台规则,特此提醒如上。祝学习进步!

28,402

社区成员

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

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