开发者

Excel 2007 PageSetup.FitToPagesWide issue

开发者 https://www.devze.com 2022-12-24 04:51 出处:网络
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#

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 wel开发者_StackOverflowl, 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.


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

精彩评论

暂无评论...
验证码 换一张
取 消