Click here to Skip to main content
15,896,606 members
Articles / Programming Languages / Visual Basic

Printing Reports in .NET

Rate me:
Please Sign up or sign in to vote.
4.85/5 (70 votes)
26 Aug 2008CPOL11 min read 441.6K   15.6K   257  
Using the library presented, you can print reports from C# and other .NET languages
Imports ReportPrinting


Public Class ReportMakerTables
    Implements IReportMaker


    Public Sub New()
        'Add any initialization after the InitializeComponent() call

    End Sub


    Dim m_dataSet As DataSet
    Dim m_Filename As String

    Property DataSet() As DataSet
        Get
            Return m_dataSet
        End Get
        Set(ByVal Value As DataSet)
            m_dataSet = Value
        End Set
    End Property

    Property Filename() As String
        Get
            Return m_Filename
        End Get
        Set(ByVal Value As String)
            m_Filename = Value
        End Set
    End Property


    Sub MakeDocument(ByVal doc As ReportDocument) Implements IReportMaker.MakeDocument
        Dim builder As New ReportBuilder(doc)

        builder.AddPageHeader(String.Empty, m_Filename, String.Empty)
        builder.StartLinearLayout(Direction.Vertical)
        builder.DefaultTablePen = doc.ThinPen

        Dim firstTable As Boolean = True


        If m_dataSet Is Nothing Then
            builder.AddText("No data to print")
        Else
            Dim dt As DataTable
            For Each dt In m_dataSet.Tables
                If Not firstTable Then
                    builder.AddPageBreak()
                End If
                builder.AddText(dt.TableName, TextStyle.Heading1)
                builder.AddTable(dt.DefaultView, True, 100)
                builder.AddAllColumns(2, True, True)
                firstTable = False
            Next
        End If

        builder.FinishLinearLayout()

    End Sub




End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions