|
You can use the data in a DataWindow control or DataStore to create an HTML table, suitable for display in a Web browser. You access this HTML through the HTMLTable property, by calling the SaveAs function with the HTMLTable! Enumeration, or by selecting FileSave Rows As HTML Table from DataWindow Preview.
Controlling table and fonts
You control table display and stylesheet usage through the HTMLTable.GenerateCSS property:
- If HTMLTable.GenerateCSS is yes PowerBuilder creates a Table element that uses HTMLTable properties to customize table display. For example, If you specify the following properties:
HTMLTable.NoWrap=Yes HTMLTable.Border=5 HTMLTable.Width=5 HTMLTable.CellPadding=2 HTMLTable.CellSpacing=2
Describe, Modify, and dot notation
You can access these properties by using the Modify and Describe PowerScript functions or by using dot notation.
The HTML syntax in the HTMLTable property includes table formatting information and CLASS references for use with the stylesheet:
<table cellspacing=2 cellpadding=2 border=5 width=5> <tr> <td CLASS=0 ALIGN=center>Employee ID <td CLASS=0 ALIGN=center>First Name <td CLASS=0 ALIGN=center>Last Name <tr> <td CLASS=6 ALIGN=right>102 <td CLASS=7>Fran <td CLASS=7>Whitney </table>
- If HTMLTable.GenerateCSS is no PowerBuilder does not use HTMLTable properties to create the Table element. For example, if GenerateCSS is no, PowerBuilder creates the following syntax for the HTMLTable property:
<table> <tr> <th ALIGN=center>Employee ID <th ALIGN=center>First Name <th ALIGN=center>Last Name <tr> <td ALIGN=right>102 <td>Fran <td>Whitney </table>
Merging HTMLTable with the stylesheet
The HTML syntax contained in the HTMLTable property is incomplete: it isn't wrapped in <HTML></HTML> elements and it does not contain the stylesheet. The following Web.PB example sets DataWindow properties, creates an HTML stream, and returns it to the browser:
Stringls_html
ds_1.Modify & ("datawindow.HTMLTable.GenerateCSS='yes'") ds_1.Modify("datawindow.HTMLTable.NoWrap='yes'") ds_1.Modify("datawindow.HTMLTable.width=5") ds_1.Modify("datawindow.HTMLTable.border=5") ds_1.Modify("datawindow.HTMLTable.CellSpacing=2") ds_1.Modify("datawindow.HTMLTable.CellPadding=2")
ls_html = "<HTML>" ls_html += & ds_1.object.datawindow.HTMLTable.StyleSheet ls_html += "<BODY>" ls_html += "<H1>DataWindow with StyleSheet</H1>" ls_html += ds_1.object.DataWindow.data.HTMLTable
ls_html += "</BODY>" ls_html += "</HTML>"
return ls_html
This technique provides control over HTML page content. Use this technique in Web.PB to create HTML dynamically or as an alternative to calling the SaveAs function with the HTMLTable! Enumeration.
Calling the SaveAs function
As an alternative to creating HTML pages dynamically, you can call the SaveAs function with the HTMLTable! Enumeration.
ds_1.SaveAs & ("C:\TEMP\HTMLTemp.htm", HTMLTable!, TRUE)
This creates an HTML file with the proper elements, including the stylesheet:
<STYLE TYPE="text/css"> <!-- .2{COLOR:#000000;BACKGROUND:#000000;FONT-STYLE:normal;FONT-WEIGHT:normal;FONT:9pt "Arial", sans-serif;TEXT-DECORATION:none} .3{COLOR:#000000;BACKGROUND:#000000;FONT-STYLE:normal;FONT-WEIGHT:normal;FONT:8pt "MS Sans Serif", sans-serif;TEXT-DECORATION:none} .3{COLOR:#000000;BACKGROUND:#000000;FONT-STYLE:normal;FONT-WEIGHT:normal;FONT:8pt "MS Sans Serif", sans-serif;TEXT-DECORATION:none} --> </STYLE> <table nowrap cellspacing=2 cellpadding=2 border=5 width=5> <tr><td CLASS=2 ALIGN=right>Employee ID: <td CLASS=3 ALIGN=right>501 <tr> <td CLASS=2 ALIGN=right>Last Name: <td CLASS=3>Scott <tr> <td CLASS=2 ALIGN=right>First Name: <td CLASS=3>David <tr> <td CLASS=2 ALIGN=right>Status: <td CLASS=3>Active </table>
Saving rows in DataWindow painter preview
You can also create an HTML file from a DataWindow object by opening the object in the DataWindow painter, previewing the object, selecting FileSave Rows As from the menu bar, and choosing the HTML Table file type.
|