FitToPagesTall and FitToPagesWide behaviour

Hi,

As per our requirement we need to read the FitToPages and FitToPagesTall values from the template file and set them to the output sheet, while doing so we are always getting the values as 1 even if the template is showing "Automatic", I am finding this as a weird behaviour .

I have created a new workbook through Aspose from an application, it comes up with a sheet say " sheet1", if I retrieve the values of FitToPagesTall and FitToPagesWide for this worksheet "sheet1" using sheet1.PageSetup.FitToPagesWide and sheet1.PageSetup.FitToPagesTall they are displayed as 1 for both of them, now I am saving the workbook on to the disk using Save method and then when I open the workbook using Excel the values displayed for both FitToPagesTall and FitToPagesWide on the "PageSetup" tab of the excel are "Automatic", shouldn't it be 1?

Similar is the behaviour when I create a workbook using Microsoftexcel and save it to disk, now if we open the workbook through aspose, the properties FitToPagesTall and FitToPagesWide are having 1, while the worksheet on the disk is having "Automatic".

Once if we change the values of any one property say FitToPagesWide to 1, save the file to disk and then check the other values through the aspose application then it is getting displayed 0 for FitToPagesTall.

Is this the expected behaviour or am I missing any thing?

Thanks & Regards,

Padmaja

Hi,

Thanks for providing us details.

We will investigate and look into your issue and get back to you soon. Your issue is logged into our issue tracking system with an issue id:
CELLSNET-17823.

Thank you.

Hi,

In MS Excel, there are two ways to scale the worksheet for Printing the worksheet : Adjust to zoom and Fit to page(s). The default mode is the adjusting to zoom. So, please use the property PageSetup.IsPercentScale as false, or you can set FitToPagesTall and FitToPagesWide again.

Thank you.

Hi Amjad,

Thanks for you help.

What will be the value of "IsPercentScale" property when we set both the FitToPagesTall and FitToPagesWide to false from the code, In my sample appliaction it is still showing as "False", but this is not the same behaviour in excel, in excel as we set "FitTo Pages wide and Tall value to 0 or "Automatic" the "Adjust to normal size "property becomes enable and selected one i.e. it is setting it self to True. Can you please let me know what should be the proper behaviour?

Thanks & Regards,

Padmaja

Hi,

Please see some code segments how to adjust one page wide and tall accordingly.

e.g

// Create a PageSetup object.
Aspose.Cells.PageSetup pagesetup = worksheet.PageSetup;
// Adjust to one page wide to scale the contents.
pagesetup.FitToPagesWide = 1;
pagesetup.FitToPagesTall = 0;


// Create a PageSetup object.

Aspose.Cells.PageSetup pagesetup = worksheet.PageSetup;

// Adjust to one page tall to scale the contents.

pagesetup.FitToPagesWide = 0;

pagesetup.FitToPagesTall = 1;


Note: When you choose to set FitToPagesWide or FitToPagesTall to 0 value, it means you are not setting any attribute value for it.


Thank you.

Having struggled with the same issue, I think I have an understanding now that is clear which I’m sharing for future search hits.

IsPercentScale dictates whether the FitToPages properties or the Zoom property should be used.

If IsPercentScale = true then don’t even consider the values of the FitToPages properties, because they are not in use. In this case the Zoom property is in use.

If IsPercentScale = false then the FitToPages Properties apply and the Zoom property is irrelevant.

Note about Excel differences: The Excel ribbon reads Automatic Wide, Automatic High and 100% scale. But Aspose reads 1 wide x 1 high, why the difference?

Excel is lying to you. If you press the page setup button in the ribbon you’ll see why. In that screen there is a radio button group and the Scale option (IsPercentScale) is set so the FitTo settings don’t matter. In the disabled FitTo section you can see the true 1 wide and 1 high as it shows in Aspose. But the ribbon doesn’t tell you which fields (fit to or scaling) are in play so it shows you the effective value, not the absolute value. Annoying, but makes sense now.

So, like in my case if you want to know if any FitToPages is not automatic then you need to evaluate:
(!worksheet.PageSetup.IsPercentScale) && (worksheet.PageSetup.FitToPagesWide > 0 || worksheet.PageSetup.FitToPagesTall > 0)

Hope this is useful down the line.
Thanks!
-Andy

@weissa,

Thanks for sharing your experience and details about the IsPercentScale, FitToPagesWide, and FitToPagesTall attributes. It may help other users as a reference.