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.
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With