We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Header and footer won't get repeated

Hi Guys,

I'm using Excel sheet to represent my PDF report. I fill a dataset the use the Excel sheet to define the layout. Then use Workbook.Save() to save it as PDF.
All that is a normal business as usual, but there is one thing that is diffent in this report.

The number of columns in the excel sheet is dynamic - I can have anything between 1 to 400 columns. The sheet also has a definition for header and footer.

The problem happens when I have more columns added to the report that can be fit in one landscape A4. In this case the header and footer won't get repeated into the second page onwards.

How can I repeat them ?

I have provided an example project that demonstrates the error - see attached project.

Regards,

Vesa Palmu

Hi,


Thanks for the sample project.

I have tested your scenario/ case using your sample project. I have analyzed your template file (where you have specified “$1:$5” as rows to repeat at top in PageSetup dialog box) and output PDF which is fine. Well, this is MS Excel behavior and the issue is nothing to do with Aspose.Cells APIs. For confirmation, you may just save the file to XLSX file format as well, i.e., just add a line to your code segment:
e.g
Sample code:

//Process the smart markers
designer.CalculateFormula = true;
designer.Process(false);

designer.Workbook.Save(Directory.GetCurrentDirectory() + @"…\Pdfs" + newFile + “.xlsx”, SaveFormat.Xlsx);

newFile = Directory.GetCurrentDirectory() + @"…\Pdfs" + newFile + “131.pdf”;
using (var stream = new FileStream(newFile, FileMode.Create))
{
designer.Workbook.Save(stream, SaveFormat.Pdf);
}

Process.Start(newFile);

Open the output Excel file and you will get the similar output as per PDF file, so it is not an issue of Aspose.Cells. When you have more columns in the report that cannot be fit in one landscape A4 page, the header and footer won’t get repeated into the second page onwards, so you may confirm this behavior in Ms Excel manually for the sample report.

By the way, for your attached project, you may try rendering all the columns to be rendered on single page by using the following line of code before rendering to XLSX or PDF.
e.g
Sample code:

//Process the smart markers
designer.CalculateFormula = true;
designer.Process(false);

designer.Workbook.Worksheets[0].PageSetup.FitToPagesWide = 1;


If you still have any doubts, kindly provide a sample Excel file that should contain your desired arrangement of header/ footer contents and you think Aspose.Cells renders to XLSX or PDF differently, let us know with the file, we will check it soon.


FYI, You cannot insert Smart Markers inside PageSetup/Headers/Footers as text as these won’t be processed. By the way, I think you may try to insert your dynamic data contents for headers/footers using the Header/ footers scripts later on once you process the markers and data is inserted into the cells of the sheet, see the document for your reference:
http://www.aspose.com/docs/display/cellsnet/Setting+Headers+and+Footers

Thank you.

Thanks for the quick reply.

I got your point, but I still have the problem :frowning:

I’m trying to look on some kind of workaround solution - and thought following idea. Currently I can fit 12 colums into the same page. So I could fix the template to have those 12 in one excel sheet (instead of just one - and adding the other columns dynamically). Then the PDF report would have 12 columns repeated on each page, right ?

It that case would the header and footer get repeated on each page ?

Hi,


Well, I am not entirely certain about your scenario and requirements, so can’t predict. Aspose.Cells renders PDF file based on what is shown in print preview of sheets in MS Excel (MS Excel built-in renderer for PDF also renders the PDF file in the same way - you may confirm it in MS Excel). If you could accomplish your requirements in MS Excel manually, you may render it in the output PDF file. Could you provide a sample Excel file (that you may manually create in MS Excel) that should contain your desired arrangement of header/ footer contents with your data, we can also help you on how to accomplish it via Aspose.Cells APIs.

Thank you.