Aspose.Cells - Insert Page Break in DataTable with repeat header

Hi,

We have a requirement of inserting pagebreaks in the datatable and on the new page the Table header should be repeated. The generated doc is to be saved in PDF format.

Attached is the sample template and the code we are using to achive this.

- In the template the data will be printed from row 11.

- In PrintPDF.cs Line 115 I am trying to insert a page break at Row 13.

When the Template and PDF is generated the xls file and PDF any of those do not have page break.

Please provide a snippet which should insert a page break at Row 13 and the generated PDF should have table header on new page as well.

Regards,

Priyank

Hi,


Thanks for the sample project.

Well, I have checked your sample project and found a flaw in your template Excel file, you have already set Fit to pages tall and Fit to pages wide option in PageSetup for your worksheet(s), so even if you insert pages breaks it would not take effect. Kindly remove this option or choose set scaling option, so your page breaks should be taken into account. I have modified/updated your code segment in " PrintPDF.cs" file a bit, see the sample code snippet below. I have tested with the update code and it works fine and as expected.

Sample code:

//…
//Instantiating a WorkbookDesigner object
var designer = new WorkbookDesigner { Workbook = new Workbook(templateFileName) };
DataTable lineItemTable = GetLineItemDataTable(pdata.PrintableTicketItems);
IList iTicketdata = new List();
pdata.PrintableTicketItems = null;//no need to have it in data source
iTicketdata.Add(pdata);
//Set the data source for the designer spreadsheet
designer.SetDataSource(HeaderInformation”, iTicketdata);
designer.SetDataSource(lineItemTable);

//Set the scalling to off the fit to pages tall and wide options that is already set in the template file.
designer.Workbook.Worksheets[0].PageSetup.Zoom = 60;


//Process the smart markers
designer.Process(true);
designer.Workbook.Worksheets[0].HorizontalPageBreaks.Add(13);

designer.Workbook.Save(@“modified.xlsx”);
//Saving file in pdf format on temp location
MemoryStream oPDF = new MemoryStream();
designer.Workbook.Save(oPDF, SaveFormat.Pdf);
return oPDF;
//…