Live SpreadsheetGear API Samples
Page Setup and Printing Samples Zoom and FitToPages
Demonstrates manually setting the Zoom for the printed output of a worksheet, as well as utilizing the "Fit To Pages" feature to have a Zoom value automatically calculate based on the desired width (number of pages across) of the printed contents.
// Create a new workbook and some local variables.
SpreadsheetGear.IWorkbook workbook = SpreadsheetGear.Factory.GetWorkbook();
SpreadsheetGear.IWorksheet worksheet = workbook.ActiveWorksheet;
SpreadsheetGear.IRange cells = worksheet.Cells;
SpreadsheetGear.IPageSetup pageSetup;
// Zoom sample
{
// Setup some sample data.
cells["A1:C10"].Formula = "=ROW()+COLUMN()";
cells["A1:C10"].Borders.LineStyle = SpreadsheetGear.LineStyle.Continuous;
// Get reference to worksheet's page setup object
pageSetup = worksheet.PageSetup;
// Set Zoom to desired value (between 10% and 400%).
pageSetup.Zoom = 325;
}
// FitToPages
{
// Add a new worksheet and populate with some sample data that would normally
// horizontally overflow into extra pages when printed.
worksheet = workbook.Worksheets.Add();
cells = worksheet.Cells;
pageSetup = worksheet.PageSetup;
cells["A1:Z200"].Formula = "=ROW()+COLUMN()";
// Automatically Scale the page contents so that it fits on one page across.
pageSetup.FitToPagesWide = 1;
// Don't attempt to auto fit vertically.
pageSetup.FitToPagesTall = 0;
// Enable FitToPages.
pageSetup.FitToPages = true;
}
Run This Sample
Download File
Download an Excel Open XML Workbook (*.xlsx) file with the results of this sample.
Related Samples
Page Setup and Printing Samples