Click here to Skip to main content
15,891,316 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 440.6K   15.6K   257  
Using the library presented, you can print reports from C# and other .NET languages
using System;
using System.Data;
using System.Drawing;
using ReportPrinting;

namespace ReportDocumentTesting
{
	/// <summary>
	/// Shows a table with gridlines
	/// </summary>
	public class ReportTest11 : IReportMaker
	{

		public void MakeDocument(ReportDocument reportDocument)
        {
            TextStyle.ResetStyles();

            TextStyle.Heading1.Size = 22;
            TextStyle.Heading1.Bold = false;
            TextStyle.TableHeader.BackgroundBrush = Brushes.DarkBlue;
            TextStyle.TableHeader.Brush = Brushes.LightGoldenrodYellow;
            TextStyle.TableHeader.MarginNear = 0.1f;
            TextStyle.TableHeader.MarginFar = 0.1f;
            TextStyle.TableHeader.MarginTop = 0.05f;
            TextStyle.TableHeader.MarginBottom = 0.05f;
            TextStyle.TableRow.MarginNear = 0.1f;
            TextStyle.TableRow.MarginFar = 0.1f;
            TextStyle.TableRow.MarginTop = 0.05f;

            ReportBuilder builder = new ReportBuilder(reportDocument);
            builder.StartContainer(new LinearSections());

            Pen innerPen = new Pen (Color.Green, 0.02f);

            DataView dv = SampleReportMaker1.GetDataView();
            ReportSectionData data;

            builder.AddTextSection ("Table with lines using default lines\n");
            // Following line sets up the pen used for lins for tables
            builder.DefaultTablePen = reportDocument.ThinPen;
            data = builder.AddDataSection (dv, true);
            builder.CurrentSection.HorizontalAlignment = HorizontalAlignment.Center;
            builder.CurrentSection.UseFullWidth = true;
            builder.AddColumn("FirstName", "First Name", 1.8f, true, true);
            builder.AddColumn("LastName", "Last Name", 1.8f, true, true);
            builder.AddColumn("Birthdate", "Birthdate", 1.8f, true, true);

            builder.AddTextSection ("\nTable with lines using some customization\n");
            data = builder.AddDataSection (dv, true);
            builder.CurrentSection.HorizontalAlignment = HorizontalAlignment.Center;
            builder.CurrentSection.UseFullWidth = true;
            builder.AddColumn("FirstName", "First Name", 1.8f, true, true);
            builder.AddColumn("LastName", "Last Name", 1.8f, true, true);
            builder.AddColumn("Birthdate", "Birthdate", 1.8f, true, true);
            data.InnerPenHeaderBottom = null; // no pen below header
            data.OuterPens = reportDocument.NormalPen;


            Pen colPen = new Pen (Color.Gray, 0.05f);
            TextStyle headerRow2 = new TextStyle (TextStyle.TableHeader);
            headerRow2.BackgroundBrush = null;
            headerRow2.Brush = Brushes.DarkBlue;

            builder.AddTextSection ("\nTable with lines using all customized stuff\n");
            builder.DefaultTablePen = null; // no default pen
            data = builder.AddDataSection (dv, true);
            builder.CurrentSection.HorizontalAlignment = HorizontalAlignment.Center;
            builder.CurrentSection.UseFullWidth = true;
            builder.AddColumn("FirstName", "First Name", 1.8f, true, true);
            builder.CurrentColumn.RightPen = colPen;
            builder.CurrentColumn.HeaderTextStyle = headerRow2;
            builder.AddColumn("LastName", "Last Name", 1.8f, true, true);
            builder.CurrentColumn.RightPen = colPen;
            builder.CurrentColumn.HeaderTextStyle = headerRow2;
            builder.AddColumn("Birthdate", "Birthdate", 1.8f, true, true);
            builder.CurrentColumn.HeaderTextStyle = headerRow2;
            data.InnerPenHeaderBottom = new Pen (Color.Red, 0.05f);
            data.OuterPens = reportDocument.NormalPen;
            data.InnerPenRow = reportDocument.ThinPen;

        }



	}
}

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