Header value of a section overlaps the other 2 sections

If i set a longer title as header on an element (section), say middle, it will go on other elements as well, which shouldn’t. Code sample:
Workbook book = new Workbook();
Worksheet worksheet = book.Worksheets[0];
worksheet.Cells[0, 0].PutValue(“Hello world”);

            PageSetup pageSetup = worksheet.PageSetup;
            Cells cells = worksheet.Cells;

            string headStr = "Test testing Test testing Test testing" +
                " Test testing Test testing Test testing Test testing Test testing";

            pageSetup.SetHeader(0, $"&\"Times New Roman,Bold\"ParkMap");
            pageSetup.SetHeader(2, "&\"Times New Roman,Bold\"&D &T");
            pageSetup.SetHeader(1, $"&\"Times New Roman,Bold\"{headStr}");

            book.Save(@"C:\Temp\Sample.pdf");

Header_Issue.png (18.2 KB)

@Remus87,

I tested your scenario/case a bit. This is same as MS Excel. So, Aspose.Cells works the same way as MS Excel does. Please note, when you have long header text/string in single line, it may overwrite other elements/sections. For your case, you need to embed line break/new line accordingly in the long text/string. See the updated sample code that works fine as I tested:
e.g.
Sample code:

Workbook book = new Workbook();
Worksheet worksheet = book.Worksheets[0];
worksheet.Cells[0, 0].PutValue(“Hello world”);

PageSetup pageSetup = worksheet.PageSetup;
Cells cells = worksheet.Cells;

string headStr = "Test testing Test testing Test testing" + "\n" +
                " Test testing Test testing Test testing Test testing Test testing";

pageSetup.SetHeader(0, $"&\"Times New Roman,Bold\"ParkMap");
pageSetup.SetHeader(2, "&\"Times New Roman,Bold\"&D &T");
pageSetup.SetHeader(1, $"&\"Times New Roman,Bold\"{headStr}");

book.Save(@"C:\Temp\Sample.pdf");

Let us know if you still have any issue.

Yes, i’m aware that can be done with a line feed if know the string length, but in our case the string will come dynamic and no string length known.
Can do few operations as find the middle of string and place the line feed there…but thought should be a property that can e set on that header element.
That’s fine than.
Thanks for the quick reply

@Remus87,

Yes, you may insert a line feed/break by yourselves for your requirements. Should you have further queries or comments, feel free to write us back. We will be happy to assist you soon.

@Remus87

Actually, the left section, center section, right section of header/footer use the same rectangle as the bound. The left section aligns to left, center section aligns to center and right section aligns to right of the “Bound rectangle”. That’s why the sections overlaps when a single text line is too long.

You may try the following approach:

  1. get page/paper width according to paper size in page setup.
  2. minus left and right margins in page setup from the page width to get the “Bound rectangle” width.
  3. split the “Bound rectangle” width to three parts for left, center, right sections as you desired.
  4. measure text width and add new line according to the section width you set in the last step.
  5. set the new line added text to the header/footer sections.

thanks for the hints Peyton !

@Remus87,

You are welcome. Feel free to write us back if you have further queries or comments, we will be happy to assist you soon.