ASP implementation display spreadsheet data in the Web (ii) Generate HTML table (turn)

Source: Internet
Author: User
Tags html page first row
web| spreadsheet | Generate html| Data | The last step in the display process is to format the data and display it, which is to create an HTML output, as follows:

Loop through each field (field) in a Recordset (recordset), and write a title
Loop the recordset and each field sequentially, and write the values
The routine code combines the entire HTML table into a long string and finally prints to the HTML page. The string is initialized to the following values:

DataTable = "< table >< TR >"

The necessary information for the columns of the spreadsheet is generated by the field collection of the Recordset object, which includes a series of field objects that can be used to establish the header row with their Name property.

For each ofield in Ors.fields
DataTable = DataTable & "< th >" & ofield.name & "</th >"
Next
DataTable = DataTable & "</tr >"

The most recently opened Recordset (Recordset) automatically points the initial position to the first row, using the MoveNext method to move the record pointer, sequentially accessing each row until the end of the recordset. When you go to the end of the recordset, the value of the attribute EOF becomes true, and the loop ends. In a loop, access to cell data is achieved through the enumeration of field collections and the corresponding Value property.

Do as not ors.eof
DataTable = DataTable & "< tr >"

For each ofield in Ors.fields
DataTable = DataTable & "< td >" & Ofield.value & "</td >"
Next

DataTable = DataTable & "</tr >"
Ors.movenext
Loop

Finally, add HTML to the table end tag, output the entire string to the page, forming a dynamically generated table. The Recordset object is freed because it is no longer needed.

DataTable = DataTable & "</table >"
Set ORs = Nothing

Response.Write DataTable

Before summing up, it is necessary to explain how a small definition is explained in the spreadsheet.

In general, in ADO, the first line in a certain range is interpreted as a set of column headings, although it is prohibited by explicitly defined options in ODBC, but I do not intend to do so in ADO. If the first line contains digital information, then ADO will return a generic field name, such as F1,F2, and so on ..., so you can't see the value of the number. Also, ADO replaces the "non-alphabetic, non-numeric" characters in the first line with the symbol #.



Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.