The HTML capabilities that were introduced to the DataWindow in PowerBuilder 7 are quite often misunderstood. Some people seem to think this functionality is tied to application servers (specifically the HTML DataWindow component) or even tied to EAServer. Nothing could be further from the truth. In fact, you can add the ability to save DataWindows, with their full presentation layer in tact, to your typical client/server application.
This means you’ll be able to transfer a file that looks like your DataWindow in your application, that can be read by anything that can read an HTML file. No need to distribute PSR viewers. Anyone with a browser or a word processor can see your data as you painted it in the DataWindow painter. Of course, the success of this will depend on the success of the end application to read HTML. In my experiments with Microsoft Word, I’ve found that Word will create temporary bitmaps for any graphical elements, and not be particularly intelligently reused. So, if each row has three radio buttons, and your report has 1,000 rows, Word is going to generate 3,000 temporary graphics to represent them. This is both slow loading and requires a significant amount of disk storage.
There are two catches with this. First is that this algorithm only supports those DataWindow types that are supported by the HTML DataWindow functionality. This excludes graph, OLE and richtext DataWindows, as well as nested and composites. The other is that the DataWindow, by itself, will not generate a full HTML page (which is what is needed by applications to read), so you will need to add HTML code before and after to make your output a proper page.
While this implementation is PFC-oriented, it should take very little effort to adapt the algorithm to non-PFC architectures.
In a new menu item, add the code:
In u_dw, create an event ue_SaveAsHTML, and add the script:
String ls_PathName, ls_FileName, ls_HTML
// Prompt the user with a File Save dialog.
li_Value = GetFileSaveName ("Save HTML File", ls_PathName, ls_FileName, "HTML", "HTML Files (*.HTML),*.HTML")
// If the user choses a file, then use it to save the HTML DataWindow
IF li_Value = 1 THEN
f_SetFileSrv (lnv_File, TRUE)
ls_HTML = "<!DOCTYPE HTML PUBLIC ~"-//W3C//DTD W3 HTML//EN~"> ~r~n<HTML>~r~n<HEAD>~r~n</HEAD>~r~n<BODY>~r~n"
ls_HTML += Describe ("DataWindow.data.html")
ls_HTML += "~r~n</BODY>~r~n</HTML>"
li_Value = lnv_File.of_FileWrite (ls_PathName, ls_HTML, FALSE)
IF li_Value < 0 THEN MessageBox ("Save HTML File", "Error saving file: " + String (li_Value))
f_SetFileSrv (lnv_File, FALSE)
This implementation is very rudimentary. There are many attributes to control what the DataWindow generates. There is also opportunity to put the output of two DataWindows on one page, creating a sort of composite.