Skip to content

Footer/Header - Spaces after &[Page] gets lost #2240

@anianHartmann

Description

@anianHartmann

EPPlus usage

Commercial use (I have a commercial license)

Environment

Windows

Epplus version

8.4.0

Spreadsheet application

Excel

Description

I got an Excel with an Footer "Seite &[Seite] von &[Seiten] / page &[Seite] of &[Seiten]".
It is displayed as "Seite 1 von 1 / page 1 of 1".

If I open Excel with EPPLUS. Then access the footer and save it under an new name, the space before "von" and "of" is missing: "Seite 1von 1 / page 1of 1"

This is a minimal sample to reproduce the code.

 ExcelPackage.License.SetNonCommercialPersonal("<Your Name>");
using var package = new ExcelPackage("Sample.xlsx");

// This Line does remove the white space before "von" and "of"
 _= package.Workbook.Worksheets.First().HeaderFooter.OddFooter.LeftAlignedText;

package.SaveAs("Sample_EPPLUS.xlsx");

Sample.xlsx

Sample_EPPLUS.xlsx

I think the error comes from recent changes in ExcelHeaderFooterTextCollection.cs.

If I change this code:

 else if(writeFormatCode && temp.FormatCode == ExcelHeaderFooterFormattingCodes.PageNumber)
     {
          if (hfText[i] == '+' || hfText[i] == '-')
           {
               temp.PageNumberSuffix += hfText[i]; 
            }
             i++;
                        
            while (char.IsDigit( hfText[i]))
            {
                temp.PageNumberSuffix += hfText[i];
                 i++;
             }                      
        }

to

else if(writeFormatCode && temp.FormatCode == ExcelHeaderFooterFormattingCodes.PageNumber)
   {
        if (hfText[i] == '+' || hfText[i] == '-')
       {
           temp.PageNumberSuffix += hfText[i];
                                            i++;
           while (char.IsDigit( hfText[i]))
           {
               temp.PageNumberSuffix += hfText[i];
               i++;
            }
         } 
    }

it is working again.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions