User Guide Cancel

spreadsheetSetFitToPage

 

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)
spreadsheetSetFitToPage(spreadSheetObject,fitToRange,pagesWidth,pagesHeight)
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>
<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>
<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>
<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>
<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>

Get help faster and easier

New user?