Recommended: Data operation of ASP rapid development method This is my own experience, for you to refer to. My goal is to make development simple, consider implementation statements as few as possible, and devote more energy to thinking about business logic. I hope my article will inspire and help you. OK, let's get to the point:
Learn how to build an ASP page to stream HTML data to an Execl spreadsheet and display the Execl spreadsheet in IE.
So far, there are several ways to create Excel data tables using ASP technology, and you can also use the server-side Excel 8.0 VBA components to create spreadsheets. However, in some cases, the server may not be able to handle the amount of information involved or bear the workloads formed, so you have to sacrifice some of the processing performance provided to the client. This article will mainly discuss the data table processing issues related to the client. Excel 97 has certain special performance that can process HTML format data streams like processing spreadsheets. This special processing capability is only available in Excel 97 or later, and users need to establish data streams similar to Excel spreadsheets to process them more effectively.
So, does the browser also have similar functions? Internet Explorer (IE) 3.0 or later can display Microsoft Excel worksheets like Excel, provided that the client needs Excel to be installed. If the user opens IE browser and enters the Excel worksheet file name as the URL, IE will open the worksheet. IE uses the file extension to identify whether it is a mime format file and starts the corresponding application. When IE processes an Excel mime format file, IE converts the file into application/vnd.ms- excel and starts Excel for users to view relevant table data.
This article will discuss how to create an ASP homepage that can deliver HTML data streams to Excel spreadsheets. Using this technology, IE browser can display HTML data tables like Excel. In the following example, the ASP homepage will launch a component that can process employee table records stored in NWIND SQLSever 6.5 while displaying the table as an HTML table.
Create HTML tables
First, create the ASP homepage and add the homepage to the Visual InterDev project. The file name is ContentType.asp, as shown in Figure A. Then add the code displayed in code A to the home page, and the first line of code can convert the mime type of the involved home page into an Excel mime type. The following lines of code will start the component we created earlier to get data from the ADOR record area. These codes, as shown in ListingA, will be processed in the record area and create an HTML table that includes records for each row in the employee table.
Code for adding new ASP page to Visual InterDev Project
<%@ Language=VBScript %>
<%Response.ContentType = application/vnd.ms-excel%>
<%
Dim objEmployee, rs
set objEmployee=server.CreateObject(EmpReport.Employee)
Set rs = objEmployee.GetEmployee()
'Draw a Table
%>
<TABLE>
<TR>
<TD><STRONG><FONT FACE= size=4>Employee
Report</FONT></STRONG></TD>
</TR>
<TR>
<TD>Employee Id</TD>
<TD>First Name</TD>
<TD>Last Name</TD>
<TD>Title</TD>
</TR>
<%
Do while not rs.eof
%>
<TR>
<TD>
<%=rs(EmployeeId)%></TD>
<TD>
<%=rs(LastName)%></TD>
<TD>
<%=rs(FirstName)%></TD>
<TD>
<%=rs(Title)%></TD>
</TR>
<%
rs.movenext
loop
%></TABLE>
After you have finished entering the code, save and browse the home page. The homepage is like Figure B. Note that all rows in this spreadsheet are not formatted. When we use Excel VBA components to create worksheets, we can use VBA to adjust the tables. However, it is difficult to format the table in the usual way using HTML, unless you can easily display and read the data about the HTML table. With ASP homepage technology, we can do this and implement all the features currently supported by Microsoft Excel, including SUM. It should be noted that worksheets created with HTML do not include some standard markup symbols, such as <HTML> and <BODY>. When we create HTML tables that exchange data with Excel worksheets, try not to use <HTML>, <BODY>, <HEAD> and other markers in the ASP homepage, because Excel worksheets usually fail to correctly these markers.
Using standard Excel features in HTML tables
Excel 97 allows users to use the calculation formulas in Excel to implement standard calculation processing in HTML tables, such as using total and sum operations functions. The significant advantage of taking advantage of this feature is that moving worksheets that require computing processing to be processed to the client will greatly reduce the use of valuable server resources and also reduce the network burden of implementing information transfer between the server and the client. For example, the home page named sumit.asp shown in Figure C, the created HTML table shows the sum of the two columns in the Excel worksheet. Please note the code in code B. The first line of code converts the content format in the table to Excel format. In this way, the browser will know which type of application is passing data for HTML tables. We create a table with two columns, and the second column row includes two sets of values: 2 and 3. The values in the third row are the sum of the first two values, and the =sum(b1:b2) calculation function of Excel is used here.
Code for creating an HTML table that displays sum of two columns in Excel worksheet
<%@ Language=VBScript %>
<%Response.ContentType = application/vnd.ms-excel%>
<TABLE>
<TR>
<TD></TD>
<TD><!-- Cell : B1 -->2</TD>
</TR>
<TR>
<TD></TD>
<TD><!--Cell : B2 -->3</TD>
</TR>
<TR>
<TD><STRONG>Sum</STRONG></TD>
<TD>=SUM(B1:B2)</TD>
</TR>
</TABLE>
Conclusion There are several different ways to display Excel worksheets using browser applications. Which method to use depends on different circumstances: Is the data processing you want to implement on the client or on the server? Do multiple formatting processes need to be done during the program operation? Is the end user using IE browser? If your worksheet is complex and very important, it is best to consider creating an Excel template and then use server-side VBA COM to fill in the values. If your worksheet is simpler or just run processing on the client side, you can consider using HTML data stream processing. On the other hand, if your user is using the Netscape Navigator browser, then all your data processing must be run on the server side and use the COM VBA component.
Share: ASP instance: Instant display of current page viewers ASP realizes instant display of the current page viewer number of people online.asp file is the referenced content: <!--#include file=dbconn.asp --><%onlineTimeout=10