Welcome,
 Guest User.

  Click to Login   


 FarPoint HOME
 clubFarPoint HOME

SUPPORT
   Forum
   View Your Questions

RESOURCES
   Search
   Articles
   Product Docs
   FAQ
   Training Videos
   Feature Suggestions
   Subscriptions
   User Groups
   FarPoint Blog

DOWNLOAD
   Updates
   Trials

MY ACCOUNT
   Member Benefits
   MVP Status
   RSS Feeds
   Register Product
   View Products
   View Orders
   Order Now
   My Profile
   Product Profiles

   clubFarPoint Feedback...


There are 17 registered members online.


   

Articles
<< Return to Articles
Printing Multiple Sheets on a Printed Page
Submitted By: Bill Albing Last Updated: 5/30/2007 12:41:47 PM
Level: Intermediate  
Product(s): Spread for Windows Forms 2, Spread for Windows Forms 2.5 for VS2002/2003, Spread for Windows Forms 2.5 for VS2005  
Language(s): C#, Visual Basic.NET  
Description: Typically, only one sheet of the spreadsheet is printed on one piece of paper using the default printing settings, but you can configure various kinds of layout such as printing multiple sheets per page by customizing the printing settings.  
 

To view a printable version of this article in a PDF viewer, click here for PDF.

Introduction

Typically, only one sheet of the spreadsheet is printed on one piece of paper using the default printing settings, but you can configure various kinds of layout such as printing multiple sheets per page by customizing the printing settings. In the following sample program, two FarPoint Spread controls are placed on a form where two sheets per one page printing is implemented by specifying output positions of respective sheets at printing. This is done by creating a subclass that implements System.Drawing.Printing.PrintDocument class. The figures below show the two controls on a form, and the result of printing them on a single page.


[Picture of two spreadsheet controls on a single Windows Form]

Two spreadsheet controls on a single Windows Form.


[Picture of result of printing both on a single page]

Result of both printed to a single page.


C# Code

 

  //Create a new instance of PrintPreviewDialog control.
  private PrintPreviewDialog PrintPreviewDialog1 = new PrintPreviewDialog();

  private void Form1_Load(object sender, System.EventArgs e)
  {

   fpSpread1.ActiveSheet.RowCount = 5;
   fpSpread1.ActiveSheet.ColumnCount = 6;
   fpSpread1.ActiveSheet.DefaultStyle.CellType = new FarPoint.Win.Spread.CellType.NumberCellType();
   fpSpread1.ActiveSheet.DefaultStyle.ForeColor = Color.Red;
   fpSpread1.ActiveSheet.ColumnHeader.Rows[0].BackColor = Color.LightPink;

   for (int i = 0; i <= fpSpread1.ActiveSheet.RowCount -1 ; i++)
   {
     for (int j = 0; j <= fpSpread1.ActiveSheet.ColumnCount -1 ; j++)
     {
      fpSpread1.ActiveSheet.SetValue(i, j, i + j);
     }
   }

   fpSpread2.ActiveSheet.RowCount = 5;
   fpSpread2.ActiveSheet.ColumnCount = 8;
   fpSpread2.ActiveSheet.DefaultStyle.CellType = new FarPoint.Win.Spread.CellType.NumberCellType();
   fpSpread2.ActiveSheet.DefaultStyle.ForeColor = Color.Blue;
   fpSpread2.ActiveSheet.ColumnHeader.Rows[0].BackColor = Color.LightCyan;

   for (int i = 0; i <= fpSpread2.ActiveSheet.RowCount -1 ; i++)
   {
     for (int j = 0; j <= fpSpread2.ActiveSheet.ColumnCount -1 ; j++)
     {
      fpSpread2.ActiveSheet.SetValue(i, j, i + j);
     }
   }

  }

  private void button1_Click(object sender, System.EventArgs e)
  {

   //Configure PrintInfo of respective sheets.
   fpSpread1.ActiveSheet.PrintInfo.ShowColor = true;
   fpSpread1.ActiveSheet.PrintInfo.ShowGrid = false;
   fpSpread1.ActiveSheet.PrintInfo.ShowRowHeaders = false;
   fpSpread2.ActiveSheet.PrintInfo.ShowColor = true;
   fpSpread2.ActiveSheet.PrintInfo.ShowGrid = false;
   fpSpread2.ActiveSheet.PrintInfo.ShowRowHeaders = false;

   //Pass SPREAD controls of user defined printing class.
   OwnerPrintDocument aDoc = new OwnerPrintDocument(fpSpread1, fpSpread2);

   //Configure respective sheet titles.
   aDoc.Title1 = "FpSpread1 title";
   aDoc.Title2 = "FpSpread2 title";

   //Configure user defined printing documents to PrintPreview.
   PrintPreviewDialog1.Document = aDoc;
   PrintPreviewDialog1.PrintPreviewControl.Zoom = 0.75;

   //Display the print preview.
   PrintPreviewDialog1.ShowDialog();

  }

Classes for user-defined printing

  [Serializable()] public class OwnerPrintDocument : System.Drawing.Printing.PrintDocument //Inherit a PrintDocument class.
  {

   //Two SPREAD controls to be printed
   private FarPoint.Win.Spread.FpSpread op_Spread1;
   private FarPoint.Win.Spread.FpSpread op_Spread2;

   //Each title
   public string Title1;
   public string Title2;

   public OwnerPrintDocument(FarPoint.Win.Spread.FpSpread Spread_1, FarPoint.Win.Spread.FpSpread Spread_2) : base()
   {
     op_Spread1 = Spread_1;
     op_Spread2 = Spread_2;
   }

   protected override void OnBeginPrint(System.Drawing.Printing.PrintEventArgs ev)
   {

     //Override OnBeginPrint method.
     base.OnBeginPrint(ev);

   }

   protected override void OnPrintPage(System.Drawing.Printing.PrintPageEventArgs e)
   {

     //Override OnPrintPage method.
     base.OnPrintPage(e);

     //************************
     // Outputting FpSpread1
     //************************
     //Configure drawing positions.
     Rectangle rect1 = new Rectangle(e.PageBounds.X + 30, e.PageBounds.Y + 40, e.PageBounds.Width / 2, e.PageBounds.Height / 2);

     //Obtain the required numbers of pages.
     int cnt1 = op_Spread1.GetOwnerPrintPageCount(e.Graphics, rect1, 0);

     //Output only when pages to be printed exist.
     if (cnt1 > 0)
     {
      op_Spread1.OwnerPrintDraw(e.Graphics, rect1, 0, cnt1);
      e.HasMorePages = false;
     }

     //*******************************************
     // Draw the title on the top of FpSpread1
     //*******************************************
     RectangleF drect1 = new RectangleF();
     drect1.X = e.PageBounds.X + 30;
     drect1.Y = e.PageBounds.Y + 10;
     drect1.Width = e.PageBounds.Width / 2;
     drect1.Height = e.PageBounds.Height / 2;
     Brush b1 =new SolidBrush(Color.Red);
     e.Graphics.DrawString(Title1, new Font("MS P Gothic", 14, FontStyle.Bold | FontStyle.Italic), b1, drect1);
     b1.Dispose();

     //************************
     // Outputting FpSpread2
     //************************
     //Configure drawing positions.
     Rectangle rect2 = new Rectangle(e.PageBounds.X + 30, e.PageBounds.Y + 210, e.PageBounds.Width - 100, e.PageBounds.Height / 2);

     //Obtain the required numbers of pages.
     int cnt2 = op_Spread2.G

   

Subscribe to the RSS feed!RSS Subscribe


Click for Morrisville, North Carolina Forecast
 
Todays Trivia














FarPoint's Spread for Web Forms

     About Us | Contact UsComments & Suggestions | ©2008 FarPoint Technologies, Inc.