Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

19.11 HTML

Formatting for HTML

HTML output is inherently different from exporting to the other file formats. HTML files are meant to be viewed in a web browser and this can impose certain requirements on how you present the data to the user. You have the option of displaying the entire report in a single browser window or breaking it up into separate web pages. If you display the report on a single page, the user can view all the data at one time. But this requires a lot of scrolling to see everything. If you decide to break up the report into separate pages, you have to decide whether you will provide your own interface for navigating between the pages or whether you want page navigation links to be automatically added to the bottom of each page. Of course, doing it automatically is a much easier solution to implement, but you have to consider whether this is fits in with the design of your entire web site. Luckily, each of these options is easy to set and you can quickly play around with each one and decide what works best for each project.

HTML export isn’t listed as an option when exporting from the Windows Viewer.

Table 19-9. HTMLFormatOptions Properties.

Property Description
FirstPageNumber The first page number to export.
HTMLEnableSeparatedPages Boolean that sets whether the HTML output will put each report page on its own web page.
HTMLFileName The filename used for saving the HTML output.
HTMLHasPageNavigator Boolean that sets whether the bottom of each page should have navigation links.
LastPageNumber The last page number to export.
UsePageRange Boolean that enables/disables the use of page ranges.

Listing 19-7. Setting the format options for HTML.
Public Sub SetFormatHtml(ByVal MyReport As CrystalDecisions.CrystalReports.Engine.ReportDocument, ByVal EnableSeparatedPages As Boolean, ByVal HasPageNavigator As Boolean, ByVal HTMLBaseFolderName As String, ByVal HTMLFileName As String, ByVal UsePageRange As Boolean, ByVal FirstPageNumber As Integer, ByVal LastPageNumber As Integer)
MyReport.ExportOptions.ExportFormatType = _
CrystalDecisions.[Shared].ExportFormatType.HTML40
'Set the destination type to HTML
Dim Options As New CrystalDecisions.Shared.HTMLFormatOptions
Options.HTMLEnableSeparatedPages = EnableSeparatedPages
Options.HTMLHasPageNavigator = HasPageNavigator
Options.HTMLFileName = HTMLFileName
Options.HTMLBaseFolderName = HTMLBaseFolderName
Options.UsePageRange = UsePageRange
If UsePageRange Then
Options.FirstPageNumber = FirstPageNumber
Options.LastPageNumber = LastPageNumber
End If
MyReport.ExportOptions.FormatOptions = Options
End Sub

The listing first sets the format type to HTML. After setting the format type, create an options object and set page formatting properties. The last step this code performs is setting the page range (as discussed in the PDF format).

There are two properties that deal with the filename that should be mentioned. The HTMLBaseFolderName property sets the folder that the HTML output is saved in. However, this is a little deceiving because the export process creates another folder within the BaseFolder and puts the HTML files in this sub-folder. Unfortunately, you don’t have any control over the name of this sub-folder and it is named in the format “TEMP_” followed random characters similar to a GUID.

You also have to be aware of how the HTML files are named. If the property HTMLUseSeperatedPages is True, the pages will be named according to the following rules:

First page is the filename you specified (e.g. Report.html).

The next pages will have a number concatenated at the end (e.g. Report1.html, Report2.html…)

The last page will have the word “Last” concatenated to the end (e.g. ReportLast.html).

If you print a page range, the numbers will not match the actual page number. They second page printed will always be numbered with “1” regardless of its actual page number on the report. As an example, if you print pages 5 through 10, then the page 5 would be named Report.HTML; page 6 is named Report1.HTML; and page 10 is named ReportLast.HTML.

When looking at the files as a whole, the first page doesn’t have a number, the second page is numbered with “1” and the last page has the word “Last”.

As an example of how confusing the folder names are, Figure 19-5 shows a snapshot or an HTML report that used a base folder name of “ExportExample” and a file name of “Report”.





Figure 19-5. The folder/file naming convention for exporting HTML.

The naming convention is different if you are exporting a report that was loaded from an external file. The export process inserts an additional folder that is the name of the report. It is appended to the BaseFolderName. If you are exporting the report EmployeeList to a file and path of C:\Temp\Report.HTML, then it will be saved to C:\Temp\Employee List\Report.HTML.