Repeated header when converting excel template to pdf

aspose question.zip (191.7 KB)
In attached input file of type excel(Source template) we are considering row no 8 to 16 as footer of report.If these section is going to print in next page then i dont want to repeat header in next page, else repeat header with if data is going into next pages…
How we are going to achieve this? any suggestion.

code snippet :
excelworkbook.Worksheets[0].PageSetup.PrintTitleRows = “$5:$5”

Note :- we are using excel as our source template.Desired output and current output file is also attached.

@PolarisAP,

Could you please elaborate bit more for our reference. Also share the code you are using to populate data in the file.

Hi,
Please find the attached console AppAsposeRepeatedHeader.zip (5.5 MB)
. To convert “37375447-d6eb-4a37-b983-058ca06fd71c.xlsx” to pdf we are using below code for repeating the header in each page in pdf.
excelworkbook.Worksheets[0].PageSetup.PrintTitleRows = “$1:$5”;The issue is that when the page is having only the footer it repeats the header as well.The converted file “headerissue.pdf” has both header and footer in second page but only footer is expected. (Footer is from text “NOTE” in the second page)

@PolarisAP,
We were able to observe the issue but we need to look into it more. We have logged the issue in our database for investigation and for a fix. Once, we will have some news for you, we will update you in this topic.

This issue has been logged as

CELLSNET-46958 - Repeated header when converting excel template to pdf

@PolarisAP,
There is no way to achieve this. Because your designed footer are cell contents, when it goes to next page, your designed header will repeat. You can check it by saving it to xlsx file before saving to pdf, you will find that the generated xlsx file also repeats header on the second page in Microsoft Excel.

Hi ,
Is there any way to restrict repeat headers for some pages?
based on some conditions we can hard code condition for last page.

.

Hi Team,
I found solution .I have configure the header and footer length . Below code is working for me.

private void SetRepeatHeader()
{
if (true)
{
var printOptions = new ImageOrPrintOptions();
var pageBreaks = excelworkbook.Worksheets[0].GetPrintingPageBreaks(printOptions);

            var i = 0;
            while (i < pageBreaks.Length )
            {

                if (i == pageBreaks.Length) break;
                if (i == 0) { i++; continue; }
                if (!(pageBreaks[i].EndRow - pageBreaks[i].StartRow == 15 || pageBreaks[i].EndRow - pageBreaks[i].StartRow < 15))
                {
                    InsertHeaderRows(excelworkbook.Worksheets[0].Cells, pageBreaks[i].StartRow);
                     pageBreaks = excelworkbook.Worksheets[0].GetPrintingPageBreaks(printOptions);
                }
                i++;
            }

        }
    }

    public void InsertHeaderRows(Cells cells, int startRow)
    {
        cells.InsertRows(startRow, 5);
        cells.CopyRows(cells, 0, startRow,5 );

    }

Hi Team
Please suggest me if there is any way to hide the header rows.Like in above code i am using insert header rows .

@PolarisAP,
Please spare us little time as we are looking into this issue and will share our feedback soon.

@PolarisAP,
No, header rows can not be hidden. However, you can copy rows at page breaks. But take care that, after adding copy rows, the follow-up page beaks will be changed.