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

chinadllh 2001-07-16 05:10:31
...全文
149 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/bc087ffa872a "测控电路课后习题详解"文件.pdf是一份极具价值的学术资料,其系统地阐述了测控电路的基础理论、系统构造、核心特性及其实际应用领域。 以下是对该文献的深入解读和系统梳理:1.1测控电路在测控系统的核心功能测控电路在测控系统的整体架构扮演着不可或缺的角色。 它承担着对传感器输出信号进行放大、滤除杂音、提取有效信息等关键任务,并且依据测量与控制的需求,执行必要的计算、处理与变换操作,最终输出能够驱动执行机构运作的指令信号。 测控电路作为测控系统最具可塑性的部分,具备易于放大信号、转换模式、传输数据以及适应多样化应用场景的优势。 1.2决定测控电路精确度的关键要素影响测控电路精确度的核心要素包括:(1)噪声与干扰的存在;(2)失调现象与漂移效应,尤其是温度引起的漂移;(3)线性表现与保真度水平;(4)输入输出阻抗的特性影响。 在这些要素,噪声干扰与失调漂移(含温度效应)是最为关键的因素,需要给予高度关注。 1.3测控电路的适应性表现测控电路在测控系统展现出高度的适应性,具体表现在:* 具备选择特定信号、灵活实施各类转换以及进行信号处理与运算的能力* 实现模数转换与数模转换功能* 在直流与交流、电压与电流信号之间进行灵活转换* 在幅值、相位、频率与脉宽信号等不同参数间进行转换* 实现量程调整功能* 对信号实施多样化的处理与运算,如计算平均值、差值、峰值、绝对值,进行求导数、积分运算等,以及实现非线性环节的线性化处理、逻辑判断等操作1.4测量电路输入信号类型对电路结构设计的影响测量电路的输入信号类型对其电路结构设计产生显著影响。 依据传感器的类型差异,输入信号的形态也呈现多样性。 主要可分为...
高效的多分辨率融合技术对具有标签不确定性的遥感数据进行处理(Matlab代码实现)内容概要:本文介绍了基于Matlab代码实现的高效多分辨率融合技术,用于处理具有标签不确定性的遥感数据。该方法通过融合不同分辨率的遥感图像,提升数据的空间与光谱信息一致性,有效应对遥感数据标注不准确或模糊的问题,从而提高后续分类、检测或识别任务的精度与鲁棒性。文详细阐述了算法的核心流程,包括多尺度数据配准、特征提取、不确定性建模及融合策略优化,并提供了完整的Matlab实现代码,便于科研人员复现实验并进行二次开发。; 适合人群:具备一定遥感图像处理基础和Matlab编程能力的研究生、科研人员及从事地理信息系统、环境监测、城市规划等相关领域的技术人员。; 使用场景及目标:①应用于土地利用分类、环境变化监测、灾害评估等存在标注误差的实际遥感项目;②旨在提升遥感数据分析的准确性与可靠性,特别是在训练样本有限或标签质量较低的情况下;③为相关领域提供可复现的技术方案与代码参考。; 阅读建议:建议读者结合提供的Matlab代码逐段理解算法实现细节,重点关注多分辨率配准与不确定性融合模块的设计逻辑,同时可尝试在自有数据集上进行迁移实验以加深理解。

28,407

社区成员

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

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