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 #.