Before I worked almost exclusively on web forms, I worked quite a bit with Crystal Reports and found it clunky, but workable. When I tried to use it for web reporting, I found what I would expect to be about a page of HTML code would get about 20 pages of HTML generated. This led me to create my own HTML reports using one VB class called Html and 3 CSS classes called Report, Report1, and Invisible.
Here is the VB class:
Imports Microsoft.VisualBasic.ControlChars
Public Class Html
Public Shared BeginTablewBorder As String =
"<table border=1 cellspacing=0 cellpadding=0 width=100% class=eval1>" & CrLf
Public Shared BeginTable As String =
"<table border=0 cellspacing=0 width=100% class=Report1>" & CrLf
Public Shared BeginPBTable As String =
"<table border=0 cellspacing=0 width=100% class=Report>" & CrLf
Public Shared BeginRow As String = "<tr>" & CrLf
Public Shared EndCell As String = "</font></td>" & CrLf
Public Shared endRow As String = "</tr>" & CrLf
Public Shared endTable As String = "</table>" & CrLf
Public Shared br As String = "<br>" & CrLf
Public Shared Function BeginCellTxt
(ByVal size As Integer, ByVal span As Integer) As String
Dim result As String
result = "<td colspan=" & span.ToString &
"><font family=arial;sanserif; size=" & size.ToString & ">" & CrLf
Return result
End Function
Public Shared Function BeginCellNum(ByVal size As Integer) As String
Dim result As String
result = "<td width=33% align=right><font family=arial;sanserif; size="
& size.ToString & ">" & CrLf
Return result
End Function
End Class
Here are the CSS classes:
.report
{
page-break-before: always;
margin-left: 60px;
}
.report1
{
margin-left: 60px;
}
.invisible
{
visibility: hidden;
}
Causing pseudo-code lines, in the web form, like this representing one row of a table:
For Each trust As TrustEntity In trusts
reportHtml &= Html.BeginRow & Html.BeginCellTxt & _
trust.Name.Trim & Html.EndCell & Html.BeginCellTxt & _
bankNumber.Trim & Html.EndCell & Html.BeginCellNum & _
total.ToString("c") & Html.EndCell & Html.BeginCellNum & _
totalHours.ToString() + Html.EndCell + Html.EndRow : line += 1
reportHtml &= Me.CheckPageBreak(False)
Next
Private Function CheckPageBreak(ByVal force As Boolean) As String
Dim reportHtml As String
If line >= pageLines Or force Then
reportHtml &= Html.EndTable
reportHtml &= Html.BeginPBTable
line = 1
page += 1
End If
Return reportHtml
End Function
The CheckPageBreak method made page breaks so easy that it is hardly worth thinking about anymore, and if needed you could add input to handle whether a header displays. The above works well for a header, followed by a table of detail data. If one needs a highly formatted set of data just use Visual Studio on an aspx page to place the labels and text fields with a variable like ||name|| for each data position. Then save the HTML as a file and do a text replacement of ||name|| with your data after grabbing the HTML into a stream. Set a literal control's text to your enhanced HTML and you have a report that looks like it did in VS. With this method you can use all the looks and color that VS easily affords us. I mention this method because I haven't seen it mentioned before even though I'm sure many use it. I was very happy with this manner of doing reports and had no complaints from clients except maybe when they wanted to get involved in report design and they didn't know HTML at all. Simple reports took about one hour and I felt totally in control of the looks. Never again would a report package keep me from getting exactly what the client wanted. Maybe my only concern was that I'm not that artistic, so if my clients didn't input something creative my reports looked fairly simple usually, but the HTML code for a simple one page view was one page of HTML not 20. It would take a very good alternative to make me switch from my current HTML methods.