Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel 2007 PageSetup.FitToPagesWide issue

Tags:

c#

excel

For while I have been trying to set the Page Scaling of Excel page in a Microsoft Visual Studio project for Excel 2007 using C#

The code looks like this

private void Sheet1_Startup(object sender, System.EventArgs e)
{
    PageSetup.FitToPagesWide = 1;  
    PageSetup.FitToPagesTall = 1;
    PageSetup.Orientation = Microsoft.Office.Interop.Excel.XlPageOrientation.xlLandscape;
    PageSetup.PaperSize = Microsoft.Office.Interop.Excel.XlPaperSize.xlPaperA4;
}

The lines for PaperSise and Orientation are working well, however I can't make Excel fit data onto one page.

Am I doing something wrong ?

MSDN did not help much because they do not yet have a code sample for this language.

like image 740
adopilot Avatar asked Mar 24 '10 16:03

adopilot


1 Answers

I should have clearly read the Remarks section on the page I mentioned. It states:

"If the Zoom property is True, the FitToPagesTall property is ignored."

And my code now looks like this, works like charm

private void Sheet1_Startup(object sender, System.EventArgs e)
{
    PageSetup.Zoom = false;
    PageSetup.FitToPagesWide = 1;
    PageSetup.FitToPagesTall = 1;
    PageSetup.Orientation = Microsoft.Office.Interop.Excel.XlPageOrientation.xlLandscape;
    PageSetup.PaperSize = Microsoft.Office.Interop.Excel.XlPaperSize.xlPaperA4;         
}
like image 172
adopilot Avatar answered Oct 30 '22 09:10

adopilot