tags:

views:

256

answers:

1

For while I am trying to set Page Scaling of Excel page in Microsoft Visual Studio project for Excel2007 using C#

Code looks like

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;
        }

Lines for PaperSise and Orientation are working well but, I can't make Excel to fit data to one page.

Am I doing something wrong ?

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

+1  A: 

I should read clearly Remarks on page I mentioned It clearly says "If the Zoom property is True, the FitToPagesTall property is ignored."

And my code now looks like this, also 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;         
        }
adopilot