This is a migrated thread and some comments may be shown as answers.

Changing Print Settings - Print Preview with RadSpreadSheet

1 Answer 152 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Lloyd Johnson
Top achievements
Rank 1
Lloyd Johnson asked on 12 Apr 2017, 02:03 AM

I am successfully using Print Preview with GridView using RadSpreadSheet.  The defaults in the Print Dialog box are completely wrong for my application but I can find no resources that say how to change these defaults.

Can someone please direct me to some sample code that shows how to change the print setting defaults?

1 Answer, 1 is accepted

Sort by
0
Stefan Nenchev
Telerik team
answered on 12 Apr 2017, 01:28 PM
Hello Lloyd,

In case some other customer is looking for the same functionality,  I am here providing the information from the other thread where we have discussed the issue:

The Orientation and Margins can be controlled by setting the WorksheetPageSetup settings of each individual Worksheet within the Workbook that the RadSpreadSheet contains. I suggest you have a look at the RadSpreadProcessing documentation for more information. As a certain Workbook can contain multiple Worksheets, you can iterate over them and set their settings:
private static RadSpreadsheet CreateSpreadsheet(RadGridView grid)
{
    var workbook = CreateWorkBook(grid);
     
    return new RadSpreadsheet()
    {
        Workbook = CreateWorkBook(grid)
    };
}
 
private static Workbook CreateWorkBook(RadGridView grid)
{
    Workbook book = null;
 
    using (var stream = new MemoryStream())
    {
        if (grid != null)
        {
            grid.ExportToXlsx(stream, new GridViewDocumentExportOptions()
            {
                ShowColumnFooters = grid.ShowColumnFooters,
                ShowColumnHeaders = grid.ShowColumnHeaders,
                ShowGroupFooters = grid.ShowGroupFooters,
                ExportDefaultStyles = true
            });
        }
 
        stream.Position = 0;
 
        book = new XlsxFormatProvider().Import(stream);
    }
 
    foreach (var item in book.Worksheets)
    {
        (item as Worksheet).WorksheetPageSetup.PageOrientation = Telerik.Windows.Documents.Model.PageOrientation.Landscape;
        (item as Worksheet).WorksheetPageSetup.Margins = PageMargins.WideMargins;
    }
 
    return book;
}

I am also attaching the sample - a modified version of the Print Preview with RadSpreadSheet demo from our SDK Samples Browser.

Regards,
Stefan Nenchev
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
GridView
Asked by
Lloyd Johnson
Top achievements
Rank 1
Answers by
Stefan Nenchev
Telerik team
Share this question
or