Many times we need to convert tabular data into execl in the form of a user, and there are several ways to do it, and I'll introduce a method that takes advantage of ASP, which allows the server to dynamically create EXECL reports without consuming any server space. The method also allows multiple users to receive the data at the same time. But the method requires at least EXECL 97 support.
Needless to say, the most important thing to do in this job is to tell the browser HTTP headers to use the following code:
<%
Response.ContentType = "Application/vnd.ms-excel"
%>
Let's take a look at an example, assuming that you now have the following form of data:
Flavor qty_baked Qty_eaten Qty_sold Price
Boston 24 2 10 0.5
Jelly 24 1 12 0.5
Strawberry 36 1 15 0.5
Chocolate 24 2 6 0.75
Maple 12 1 6 0.75
Customer requirements are expressed in the form of execl and want to add some other calculated totals
Use the following code:
......
<%
Response.ContentType = "Application/vnd.ms-excel"
Set Conntemp=server.createobject ("Adodb.connection")
Cnpath= "dbq=" & Server.MapPath ("/stevesmith/data/timesheet.mdb")
Conntemp. Open "Driver={microsoft Access DRIVER (*.mdb)};" & Cnpath
Set Rs=conntemp.execute ("SELECT * from Donut")
%>
<table border=1>
<TR>
<%
' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'% Loop through Fields Names and print out the Field Names
' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
j = 2 ' Row counter
For i = 0 to RS. Fields.count-1
%>
<td><b><% = RS (i). Name%></b></td>
<% Next%>
<td><b>on Hand (Calculated) </B></TD>
<td><b>gross (Calculated) </B></TD>
</TR>
<%
' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'% Loop through rows, displaying each field
' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Do but not RS. Eof
%>
<TR>
<% for i = 0 to RS. Fields.count-1
%>
<TD valign=top><% = RS (i)%></td>
<% Next%>
<TD>=b<%=j%>-c<%=j%>-d<%=j%></TD>
<TD>=d<%=j%>*e<%=j%></TD>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service