We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

SetFitToPages back to default

Hi.
When i use SetFitToPages to show all my data on one page i am not able to back to default afterwards.
The code below generedes two identical pdf fiels where both have all data showing in one page.
Eventhough running SetFitToPages(1,1) should give me the default setup?

  var wb = new Workbook();
  var sheet = wb.Worksheets[0];

  for (int i = 0; i < 50; i++)
  {
    sheet.Cells[i,i].Value = "Data";
  }

  sheet.PageSetup.SetFitToPages(1,1);
  var filename = @"C:\Users\mjp\Desktop\AsposeTestogLeg\Excel\Live1_1.pdf";      
  wb.Save(filename);

  sheet.PageSetup.SetFitToPages(1, 0);
  var filename2 = @"C:\Users\mjp\Desktop\AsposeTestogLeg\Excel\Live1_0.pdf";
  wb.Save(filename2);

@Jull,

There is a little issue with a line in your code, so your code is wrong. Please change the line of of code:
i.e.,
sheet.PageSetup.SetFitToPages(1, 0);
to:
sheet.PageSetup.SetFitToPages(0, 0);

it will work for your needs.

Please note, if you use the line sheet.PageSetup.SetFitToPages(1, 0);, you are still trying to render fit to page(s) width wise (wide), so you need to set it off as well.

1 Like

Great. You are correct. Though it is confusing that the default values of tall and wide are 1?

No. in MS Excel “Adjust to:” option —> “100%” scaling is the default value set for the page unless you select “Fit to:” option (which is set 1 page wide and 1 page tall). So you my either use the line to set off the options via sheet.PageSetup.SetFitToPages(0, 0); (to get you to defaults) or use sheet.PageSetup.Zoom = 100; to get 100% scaling for getting back to defaults.

Hope, this helps a bit.