Free Support Forum - aspose.com

Page breaks and FitToPages

Hello!

We need to add page breaks to a document where we also need to specify the printing area. It says in the documentation that you can't use regular page breaks if you specify FitToPagesWide but can you in some way move the automatic page breaks that you see in the document? As of now we have to generate the documents and move the page breaks by hand and then send the documents to the customers and this is not a good solution.

I have tried to add regular page breaks and they are inserted in the correct places in the document but have no effect on the printing.

Is there a workaround to this problem?

Hi,

Thank you.

Yes, FitToPagesWide and FitToPageTall will override the existing page breaks in the document. This behavour is same as MS Excel. Could you elaborate your query what do you need, if possible could you create a sample test excel file with your sample code to show what is missing in Aspose.Cells and your desired output. We will check if we could enhance it .

Thank you.

If you open a generated document and select Preview page breaks ( my translation ) you see the blue dotted lines where the page breaks will end up. You can move these up or down with the cursor and save the document and they will stay in that position. Is it possible to move the page breaks programmatically in some way? This is what we would need.

Thanks for a fast reply.

Hi,

Ok, we now undestand, we will check if we could make your required feature and move those page breaks lines soon.

Thank you.

You can set the print area to move the range shown in page break view.

For example,

sheet.PageSetup.PrintArea = "A1:I19";

Then in the output file, you can see the range A1:I19 shown in the page break view.

I am fine with the print area, it’s the automatic page breaks I would like to move. You can move the automatic page breaks with the cursor and save the file and they will stay in the right place. Now I wonder if you could add the functionality to move the automatic page breaks programmatically. I assume the information is stored somewhere in the file and it’s just a matter of reading, changing and writing the info back to the file.

You can move the automatic page breaks with the cursor and save the file and they will stay in the right place.

I don't think you move the automatic page breaks but the width of a column or height of a row. In this way automatic page breaks will change according to the width change or height change. There are no any record in Excel file to save this settings. MS Excel will calculate them automatically when you open the file. That's why it's called automatic pagebreaks.

I think you can only use HPageBreaks class and VPageBreaks to add hard page breaks as in MS Excel.

Ok, I am sending you two files as an example. The first file is the one I generate with Aspose.Cells. The automatic page breaks end up as blue dashed lines at row 83 and 161. In the second file I have moved the page breaks with the cursor to row 77 and 149 to better fit my needs. The lines are now solid blue.

Since I can do it with the cursor I just assume there should be a way to do this programatically too. Is this possible to fix?

I am using Excel 2003 if that make a difference.

And the second file…

When you move the page break in page break view, a hard page breaks are created. You can use the following code:

hPageBreak.Add(77, 0, 255);

I have tried to set the page breaks with the hPageBreak.Add() method but that have no effect. The page breaks are there in the page because if I select the row where I put it I get the option to remove it but the page breaks have no effect when printing. If I move the blue dashed line on the other hand the printing works just fine.

When you drag the automatic page breaks, other page setup settings are also changed. I found that in your output file's PageSetup settings, scaling is changed from FitToPage to 45%. Please try the following code:

Workbook wb = new Workbook();
wb.Open("d:\\test\\reportoriginal.xls");
wb.Worksheets[0].HPageBreaks.Clear();
wb.Worksheets[0].VPageBreaks.Clear();
wb.Worksheets[0].HPageBreaks.Add(77, 0, 255);
wb.Worksheets[0].PageSetup.Zoom = 45;

wb.Save("d:\\test\\abc.xls");

Attached is my output file. Please check if it serves your need.

Yes, it worked. Thank you for solving this issue, it has been a great help for us.