Header is altered during PDF conversion

Hello,

we got an excel workbook with the content H&&I H&&L in the header, which is supposed to be displayed as H&I H&L.
When you convert this workbook to PDF with Excel directly, in the PDF generated by Excel, the content is correctly displayed as H&I H&L.
But using Aspose to convert to PDF the generated header is H&G H&L instead.

Please see the attached documents and example code, using Aspose.Cells 23.6.0 with a .Net 7 command line application on Windows 10.

using Aspose.Cells;

var lic = new License();
lic.SetLicense(@"S:\Aspose.Total.NET.lic");

var wb = new Workbook(@"S:\tmp\in.xlsx");

wb.Save(@"S:\tmp\out.pdf");

files.zip (54.6 KB)

Thanks for your help,
Daniel

@Serraniel

In your shared source file “in.xlsx”, the header is H&&G H&&L instead of H&&I H&&L.

Also, I tried to change the content to H&&I H&&L, it also works OK.

That´s weird. If I download and open the file with Excel it displays H&&I for me, also if I copy the text, please see the video.

Any ideas why the behaviour is like that?

video.zip (1.4 MB)

I looked into the XML. It´s kinda weird. I typed H&&I into a new workbook. But if I rename to zip and extract the XML of the worksheet it stored H&&G instead.

video2.zip (2.5 MB)

If I actually type H&&G it becomes H&&O in the XML. Not sure why it is like this, if that´s an Excel Bug or if that is something related to my Excel is localized to German.

Here is the file where I put the H&&G into it, too:
file.zip (6.5 KB)
Displayed by my Excel as:
image.png (3.2 KB)

@Serraniel,

Thanks for the videos, screenshot and Excel file.

I checked your Excel file again. I opened into MS Excel (English), my regional setting is us-english and your headers are shown as H&G and H&O. I guess your issue might be related to your locale/regional settings. Could you please share your complete environment details (e.g., OS and its version), locale and regional settings with screenshots, etc. By the way, could you please try to open your Excel file into MS Excel (English) and check if you still see any issue/difference.

And, we will evaluate your issue further and get back to you.

@Serraniel

On our side, the header displayed in Excel is consistent with the underlying XML data: Screenshot_header.png (79.8 KB)

I also tried to change my locale and Excel default editing/authoring language(Excel->Options->Language) to German(Germany), but result is same as the above sreenshot.

Could you please try to open your shared files(“in.xlsx” and “test2.xlsx”) on the other machine to see whether there are some differences?

Hello,

the system is a Windows 10 with German Language:
image.png (4.3 KB)
image.png (14.4 KB)
image.png (12.6 KB)
image.png (38.3 KB)

I also tried to change my locale and Excel default editing/authoring language(Excel->Options->Language) to German(Germany), but result is same as the above sreenshot.

Could you please try to open your shared files(“in.xlsx” and “test2.xlsx”) on the other machine to see whether there are some differences?

For me locally I get the following behaviour

Office display language Office authoring language Displayed content
System (German) German H&I
System (German) English H&I
English English H&G
English German H&G
German English H&I

So it seems to depend on the display language configured inside Excel. Kinda odd behaviour of excel…

@Serraniel

After setting Office display language to Germany, the content H&I is displayed in Excel(same as you). That’s so odd. Are there some special cases for &I, &G, &O in Germany?

We need to look into it more. If there are some progress, we will update you here.
Also, If you have some findings, please share them with us.

Hey,

I haven´t really discovered any more information. I tried to search the internet if there were bug reports in that direction but could not find any.
I tried to put &&A &&B &&C [..] &&Y &&Z in the header in a German configured Excel and save it. For some reason, while saving, the displayed O is replaced to display a G:
2023-06-16_08-38-58.zip (822.6 KB)

and this is what is stored in the file at the end
&&N &&A &&H &&D &&E &&B &&O &&S &&G &&J &&I &&L &&K &&F &&O &&Z &&Q &&R &&P &&U &&T &&V &&W &&X &&Y &&C.

I don´t know if Excel uses some weird static mapping of the characters or what they try achieve at all by this. I personally also don´t know any further functions behind these combinations.

@Serraniel,
Thanks for your feedback and details. We will evaluate your issue further and get back to you soon.

@Serraniel

It seems that it is a bug in Excel. Some words(e.g. &O) will not be displayed in Excel header in this case.

You may try to add a whitespace between && and the letter (e.g. && G, && O) to avoid this issue in Excel.

@Serraniel
And you can process header and footer before converting the file to pdf as the following :

public static void ProcessHF(PageSetup pageSetup )
      {
          for (int i = 0; i < 3; i++)
          {
              string h = pageSetup.GetHeader(i);
              if(string.IsNullOrEmpty(h))
              {
                  h = h.Replace("H&&G", "H&&I");
                  pageSetup.SetHeader(i, h);
              }
             
          }
          for (int i = 0; i < 3; i++)
          {
              string h = pageSetup.GetFooter(i);
              if (string.IsNullOrEmpty(h))
              {
                  h = h.Replace("H&&G", "H&&I");
                  pageSetup.SetFooter(i, h);
              }
                 
          }
      }

static void Main(string[] args)
      {
         
          string dir = @"d:\Filetemp\";
          Workbook workbook = new Workbook("test2.xlsx");
          ProcessHF(workbook.Worksheets[0].PageSetup);
          workbook.Save("dest.pdf");
}
1 Like