Whatever message this page gives is out now! Go check it out!

spreadsheetSetFitToPage

Last update:
May 18, 2026

Description

This function toggles the currently active sheet's "fit-to-page" print option on or off. It uses the pagesWide and pagesHigh parameters to control the number of pages to fit the columns/rows into when printed. The function adjusts the size of your data (including text, rows, columns, and graphics) to ensure that everything fits within the printable area, avoiding manual adjustments.

Returns

None

History

  • ColdFusion (2025 release): Added the function.

Syntax

spreadsheetSetFitToPage(spreadSheetObject,fitToRange,pagesWidth,pagesHeight)

Parameters

Name
Required
Type
Description
spreadSheetObject
Yes
ExcelInfo
The Excel spreadsheet object to fit to page for printing.
fitToRange
Yes
Boolean
True, to enable fit to page. False, otherwise.
pagesWidth
Yes
Integer
The number of pages to fit the sheet's columns. Specify 0 for no horizontal fit.
pagesHeight
Yes
Integer
The number of pages to fit the sheet's rows. Specify 0 for no vertical fit.

Example 1- fitToRange is True

<cfscript>
    theFile=GetDirectoryFromPath(GetCurrentTemplatePath()) & "sheet-fit-page-off.xls";
    // create a spreadsheet object
    obj=spreadsheetNew("SheetNew",true)
    // add data
    for (i=1;i<52;i++){
        SpreadsheetSetCellValue(obj,"Value1#i#",#i#,1)
        SpreadsheetSetCellValue(obj,"Value2#i#",#i#,2)
        SpreadsheetSetCellValue(obj,"Value3#i#",#i#,3)
        SpreadsheetSetCellValue(obj,"Value4#i#",#i#,4)
        SpreadsheetSetCellValue(obj,"Value5#i#",#i#,5)
    }
    spreadsheetSetFitToPage(obj,true,2,2)
    spreadsheetWrite(obj, theFile, "", "yes", "no")
</cfscript>

Example 1- fitToRange is false

<cfscript>
    theFile=GetDirectoryFromPath(GetCurrentTemplatePath()) & "sheet-fit-page-off.xls";
    // create a spreadsheet object
    obj=spreadsheetNew("SheetNew",true)
    // add data
    for (i=1;i<52;i++){
        SpreadsheetSetCellValue(obj,"Value1#i#",#i#,1)
        SpreadsheetSetCellValue(obj,"Value2#i#",#i#,2)
        SpreadsheetSetCellValue(obj,"Value3#i#",#i#,3)
        SpreadsheetSetCellValue(obj,"Value4#i#",#i#,4)
        SpreadsheetSetCellValue(obj,"Value5#i#",#i#,5)
    }
    spreadsheetSetFitToPage(obj,false,2,2)
    spreadsheetWrite(obj, theFile, "", "yes", "no")
</cfscript>

Share this page

Was this page helpful?
We're glad. Tell us how this page helped.
We're sorry. Can you tell us what didn't work for you?
Thank you for your feedback. Your response will help improve this page.

On this page