I am using Excel Interop to create a report.
I am trying to programatically set the page breaks. I’ve been successful in doing so by using:
this.ActiveWorksheet.HPageBreaks.Add(this[row + 1, 9].Range);
this.ActiveWorksheet.VPageBreaks.Add(this[row + 1, 8].Range);
(the this[row…col] code refers to our base Excel generator but ultimately refers to a range with a given column / row).
When the report generates I can see my manually added page breaks; however the automatic page breaks still show up and they’re in the wrong places so ultimately this makes my code useless. I need to make use of only my page breaks and ignore the automatic ones.
Is it possible to do so?
I’ve tried resetting the page breaks to no avail. I’ve also tried setting the FitToPagesWide property on the worksheet page setup property with no luck.
I solved the issue by setting
PageSetup.Zoom = false;before setting FitToPagesWide = 1
It appears that unless you explicitly set zoom to false, the FitToPagesWide/Tall properties are ignored.