Problem with Fit to Pages and Page Breaks

Hello -

I am having trouble setting page breaks when I also use the fit to page (both tall and wide) methods. For example, here is the code I’m using:


<—BEGIN CODE SNIPPET--------------------------->

oSheet.PageSetup.PrintTitleColumns = “$A:$B”

oSheet.PageSetup.PrintArea = “A1:” & _LastCell

oSheet.PageSetup.FitToPagesWide = 3 '(_ReportCriteria._EndYear - _ReportCriteria._StartYear) + 1

oSheet.PageSetup.FitToPagesTall = 3 ’ _dsReportData.Tables(DATA_TABLE_MEASURES).Rows.Count

For Each Cell As String In _PageBreak

oSheet.HPageBreaks.Add(Cell)

oSheet.VPageBreaks.Add(Cell)

Next

oSheet.PageSetup.Order = PrintOrderType.OverThenDown


<—END CODE SNIPPET--------------------------->


When I use the fit to page commands, the page breaks do not get set at all. If I leave out the fit to page commands, the page breaks appear, but Excel formats the additional page breaks in between my page breaks. Any help?

I just came across an article on your website that says if the fit to page commands are used, page breaks are ignored. Do you have any plans to add this functionality to Aspose.Excel? MS Excel can handle fit to page and page breaks.

Do you have any suggestions in the meantime how I can accomplish adding page breaks and also making sure I only have a set # of pages printed?

Thanks,

Brian

No. MS Excel cannot handle fit to page and page breaks at same time. You can set fit to pages option and MS Excel will automatically set page breaks and will ignore your manually set page breaks. You can verify it in MS Excel.

@McArdleAbsci,
Aspose.Cells is the latest version that has replaced Aspose.Excel which is discontinued and no more available now. You can work with page breaks using this new product easily like add a page break, remove a specific or all page breaks. Following is an example that can be referred to for working with the page breaks in an Excel file.

// Instantiating a Workbook object
Workbook workbook = new Workbook();

// Add a page break at cell Y30
workbook.Worksheets[0].HorizontalPageBreaks.Add("Y30");
workbook.Worksheets[0].VerticalPageBreaks.Add("Y30");

// Save the Excel file.
workbook.Save(dataDir + "AddingPageBreaks_out.xls");

Refer to the following article for more details on working with the page breaks.
Managing Page Breaks

The free trial version of this new product can be downloaded here:
Aspose.Cells for .NET (Latest Version)

A detailed solution is available here which can be used for testing different features of this product.