Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Thu May 11, 2023 7:22 am

Hello.

I am creating an auto-generated report using Epplus and converting it to PDF using Spire.XLS. The footer is set to
Code: Select all
"&P-1 of &N-1"
to get current page number out of total page numbers. "- 1" because I want to start the count from the second page/sheet.

My problem is that when converting to PDF with Spire the "-" sign is interpreted as a plus (+). So instead of having "1 of 5" I get "3 of 7". I tried using Aspose.Cells and that interpreted it right and I got what I wanted but I do not have a Licence for it so I get an ugly watermark. I would like to avoid turning to Aspose when I already have a Spire licence.

I could probably calculate the page numbers myself but it would be a big workaround for something that should already work. I can't count only the sheets either because some sheets have more than one page.

Am I doing something wrong or is this a bug?

lu65tkeo
 
Posts: 1
Joined: Thu May 11, 2023 6:41 am

Thu May 11, 2023 8:39 am

Hi,

Thanks for your inquiry.
I did a test with your footer code, using the latest Spire.XLS_13.4.0, the “-1” can be resolved correctly, I have attached my test code for your reference. Please use the latest Spire.XLS and have a test.
Code: Select all
            Workbook workbook = new Workbook();

            //Get the first worksheet.
            Worksheet sheet = workbook.Worksheets[0];
            sheet.Range["A1"].Text = "Hello World";
            sheet.Range["F30"].Text = "Hello World";
            sheet.Range["G150"].Text = "Hello World";

            //Set the value to show the headers/footers for first page are different from the other pages.
            sheet.PageSetup.DifferentFirst = 1;

           
            sheet.PageSetup.CenterFooter = "&P-1 of &N-1";

            String result = "Result.pdf";

            //Save to file.
            workbook.SaveToFile(result, FileFormat.PDF);

If the code does not meet your requirement or you have any further questions, please share us with your full test code and document so that we can work out a solution for you. Thanks for your assistance.

Best regards,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Return to Spire.XLS