Available for: UI for ASP.NET MVC | UI for ASP.NET AJAX | UI for Blazor | UI for WPF | UI for WinForms | UI for Xamarin | UI for WinUI | UI for ASP.NET Core | UI for .NET MAUI

New to Telerik Document Processing? Download free 30-day trial

Page Setup Exporter

The PageSetupExporter allows you to export the page settings for printing. The following methods are exposed:

  • SetFitToPagesTall: Sets the number of pages tall the worksheet will be scaled to when it's printed.
  • SetFitToPagesWide: Sets the number of pages wide the worksheet will be scaled to when it's printed.
  • SetPageOrder: Sets the page order.
  • SetPageOrientation: Sets the page orientation.
  • SetPaperSize: Sets the size of the paper.
  • SetScaleFactor: Sets the scale factor of the printed worksheet. The valid values are from 0.1 to 4.

Working with PageSetupExporter

An important part is that you need to place the PageSetupExporer after the code for exporting all cells on the sheet. Example 1 demonstrates how you can create the PageSetupExporter and where to place it.

Example 1: Using PageSetupExporter

using (FileStream stream = File.Open(fileName, FileMode.OpenOrCreate)) 
{ 
    using (IWorkbookExporter workbook = SpreadExporter.CreateWorkbookExporter(documentFormat, stream)) 
    { 
        using (IWorksheetExporter worksheet = workbook.CreateWorksheetExporter("Date")) 
        { 
            // export cells here 
 
            using (IPageSetupExporter pageSetupExporter = worksheet.CreatePageSetupExporter()) 
            { 
                pageSetupExporter.SetFitToPagesTall(2); 
                pageSetupExporter.SetFitToPagesWide(3); 
                pageSetupExporter.SetPageOrder(SpreadPageOrder.OverThenDown); 
                pageSetupExporter.SetPageOrientation(SpreadPageOrientation.Landscape); 
                pageSetupExporter.SetPaperSize(SpreadPaperSize.A5); 
                pageSetupExporter.SetScaleFactor(1.5); 
            } 
        } 
    } 
} 

IPageSetupExporter inherits from IDisposable. Make sure the object is disposed when you are done with it. Otherwise, the content won't be written in the exported file. The best way to ensure this is handled properly is to wrap it in a using statement.

In this article