Pagination is computed by a UI-independent engine (unvell.ReoGrid.Core.Printing)
shared by PDF, WinForms, and WPF. Every output target produces the same result.
Page setup
using unvell.ReoGrid.Core.Printing;
ws.PrintSettings = new PrintSettings
{
Paper = PaperKind.A4,
Orientation = PageOrientation.Portrait,
MarginLeft = 54, // ポイント(72 pt = 1 インチ)
MarginRight = 54,
MarginTop = 54,
MarginBottom = 54,
PrintArea = RangePosition.Parse("A1:H60"),
Scale = 1.0,
CenterHorizontally = true,
Order = PageOrder.DownThenOver,
ShowGridLines = true,
ShowHeaders = false,
};
Paper sizes
PaperKind is one of A5 / A4 / A3 / B5 / B4 / Letter / Legal /
Tabloid / Executive / Custom.
For Custom, specify CustomWidthPt / CustomHeightPt in points.
Scale and fit-to-page
ws.PrintSettings = new PrintSettings
{
FitToPagesWide = 1, // 横 1 ページに収める
FitToPagesTall = null, // 縦は成り行き
};
bool fit = ws.PrintSettings.IsFitToPage;
Scale ranges from 10% to 400% (MinScale / MaxScale). If either FitToPagesWide or
FitToPagesTall is set, it takes precedence over Scale.
The on-screen zoom factor (control.Zoom) has no effect on printing.
Pagination rules
- Rows and columns are never split. Just like Excel, a row that does not fit is pushed to the next page
- Hidden rows and columns are treated as zero width/height
PageOrderis the order in which pages are emitted (DownThenOver= down first,OverThenDown= across first)
Getting the page count up front
// ページ数だけ知りたい場合(描画せずに計算できる)
PrintLayout layout = Paginator.Paginate(ws, ws.PrintSettings);
Console.WriteLine($"{layout.Pages.Count} ページ");
Since no rendering is involved, this works for preview UIs and batch processing.
Calls per output target
| Output target | Call |
|---|---|
PdfExporter.Export(ws, path, settings) | |
| WinForms | control.CreatePrintDocument(settings) → PrintDocument.Print() |
| WPF | control.Print(settings) |
| Avalonia | Not supported (use PDF export) |
The WinForms version returns a PrintDocument, so you can pass it straight to the standard
print dialog or print preview.
Persistence
PrintSettings round-trips as <pageSetup> in XLSX. Opening the file in Excel gives you
the same paper, orientation, and margins.
Not supported
- Print titles (repeating the leading rows/columns on every page)
- Headers and footers (page numbers and the like)
- Printing only specific pages within the print area
- Persisting per-sheet print settings (on the reogrid-json side)
Freeze panes are a screen-display feature and have no effect on printing (Freeze Panes).
What to read next
- PDF Export
- WinForms