ReoGrid
DOCUMENT
Paging and Print

Auto Paging

When a worksheet to be printed, ReoGrid performs the worksheet paging automatically. Paging operation scans the worksheet and decides the print range for every pages according to paging settings. For example, the following image shows a worksheet has been paged vertically.

108

Like as Excel, ReoGrid finds maximum number of cells in order to fill each pages, all cells that cannot be printed out entirely will be moved to next page, for example:

109

Perform auto paging or reset page breaks

Anytime to perform an auto paging or reset current existed page breaks:

sheet.AutoSplitPage();

This method itself works very fast(<10ms.), but it may be slowed down if a remote printer is set as default printer, to fetch the paper size from a remote printer will spend more than 100ms. (depends on the network environment)

Show page break lines

To show a page break lines on screen:

sheet.EnableSettings(WorksheetSettings.View_ShowPageBreaks);

Result: 120

Auto-check printable boundary

If there is no printable range specified, ReoGrid will find the used range of cells to set the printable range automatically.

121

Change printable range

Property PrintableRange of worksheet is used to change the printable range.

sheet.PrintableRange = new RangePosition(1, 1, 9, 9);

122

If the printable range is larger than the paper size, it will be split automatically. The cell outside the printable range will not be printed out.

Change paging order

Use PrintSettings.PageOrder property to change the paging direction.

112

sheet.PrintSettings.PageOrder = PrintPageOrder.DownThenOver;

Change page setting

Property PrintSettings of worksheet is used to change paper settings.

// change page to landscape
sheet.PrintSettings.Landscape = true;

// set page margins
sheet.PrintSettings.Margins = new PageMargins(5);

Example: Auto paging to landscape

123

It is possible to set print scaling by using the property PageScaling of PrintSettings.

sheet.PrintSettings.PageScaling = 0.7f;    // scale to 70%

When page scaling is changed, the worksheet will be re-paged automatically.

Insert a page break

To insert a page break by using RowPageBreaks and ColumnPageBreaks property of worksheet:

// insert page break
sheet.ColumnPageBreaks.Add(5);

Spreadsheet is split into two pages:

124

User page breaks and system page breaks

There is two types of page breaks, solid lines are the user page breaks, generated by AutoSplitPage method or user operations; dashed lines are the system page breaks, inserted by ReoGrid automatically to split worksheet into multiple page.

125

Change page breaks

To change/move an index of page break (whatever a system or user page break), use the following methods:

void sheet.ChangeColumnPageBreak(int oldIndex, int newIndex);
void sheet.ChangeRowPageBreak(int oldIndex, int newIndex);

Once a page break is changed, it will become to user page break and will not be updated by ReoGrid automatically.

Iterate pages

Method IteratePrintPage of worksheet is used to iterate over all print pages, this method returns the range position for every pages:

sheet.IteratePrintPages( range => {
  Console.WriteLine("Page range is: " + range.ToAddress());
  return true;
});

The result is printed out:

Page range is: A1:E11
Page range is: F1:K11

It is possible to iterate pages by specified order:

sheet.IteratePrintPages(PrintPageOrder.OverThenDown, range => { ... });

If no paging order is specified, the page order of print settings will be used.

Disable end-user changing/adjusting the page breaks

To disable end-user to change the page break index by mouse, set the worksheet settings:

sheet.SetSettings(WorksheetSettings.Behavior_AllowUserChangingPageBreaks, false);

A print session used to print entire workbook or specified multiple worksheet. To print entire workbook or multiple worksheet, create print session from workbook instance (the control); To print single worksheet, create print session from that worksheet.

263

var session = worksheet.CreatePrintSession();
session.Print();
var session = reoGridControl.CreatePrintSession();
session.Print();
var session = reoGridControl.CreatePrintSession();
session.Worksheets.Clear();
session.Worksheets.Add(grid.Worksheets["Sheet1"]);
session.Worksheets.Add(grid.Worksheets["Sheet3"]);
session.Print();

The following code shows a .NET standard print preview dialog:

var sheet = reoGridControl.CurrentWorksheet;

using (var session = sheet.CreatePrintSession())
{
  using (PrintPreviewDialog ppd = new PrintPreviewDialog())
  {
    ppd.Document = session.PrintDocument;
    ppd.SetBounds(200, 200, 1024, 768);
    ppd.PrintPreviewControl.Zoom = 1d;
    ppd.ShowDialog(this);
  }
}

Print

The following code print worksheet with default print settings.

var session = sheet.CreatePrintSession();
session.Print();

The following code shows a standard print dialog then print specified worksheet.

System.Drawing.Printing.PrintDocument doc = null;

try
{
  doc = worksheet.CreatePrintSession().PrintDocument;
}
catch (Exception ex)
{
  MessageBox.Show(this, ex.Message, this.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
  return;
}

using (var pd = new System.Windows.Forms.PrintDialog())
{
  pd.Document = doc;
  pd.UseEXDialog = true;  // in 64bit Windows

  if (pd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  {
    doc.PrinterSettings = pd.PrinterSettings;
    doc.Print();
  }
}

if (doc != null) doc.Dispose();

Show system page settings dialog

using (PageSetupDialog psd = new PageSetupDialog())
{
  // transform ReoGrid page settings to System page settings
  psd.PageSettings = worksheet.PrintSettings.CreateSystemPageSettings();

  psd.AllowMargins = true;
  psd.AllowPrinter = true;
  psd.AllowPaper = true;
  psd.EnableMetric = true;

  if (psd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  {
    // transform System page settings to ReoGrid page settings
    worksheet.PrintSettings.ApplySystemPageSettings(psd.PageSettings);
  }
}

Was the content of the page helpful?

© 2012-2024UNVELL Inc.