How To Set Excel Header Font Color, Size, Bold and Name With Aspose.Cells for .Net 18.3.0.0

Hi;
We examined Setting Headers and Footers|Documentation (aspose.com) and Setting Headers and Footers|Documentation (aspose.com) this.

We could set Header and Footer on excel file. But we have problem about font color, size, name of header and footer text.

Here is ours code:

Workbook wb = new Workbook(stream);

foreach(Worksheet sheet in wb.Worksheets){
   PageSetup pageSetup = sheet.PageSetup;
   pageSetup.SetHeader(0,"Left Header Sample &\"Times New Roman\"&12");
   pageSetup.SetHeader(1,"Middle Header Sample &\"Times New Roman\"&14&KFF0000");
   pageSetup.SetHeader(2,"Right Header Sample &\"Times New Roman\"&12");

   pageSetup.SetFooter(1,"Middle Footer Sample &\"Times New Roman\"&14&KFF0000");
}

In my code, is similar to samples in yours documentaries which I share in begining of this post. But, texts writes in header and footer as “Calibri”, font size 12, font color black and not bold.

Where I am wrong? How can I do that?

Thanks a lot.

@hvkktr
Please try

   pageSetup.SetHeader(0, "&\"Times New Roman,Bold\"&12&KFF0000Left Header Sample ");

@hvkktr you can use this post as reference. Also keep in mind that there is a limitation for XLS file format (Excel 97-2003) that does not support to perform this task in it, it started to supported in MS Excel 2007 XLSX file format.

It worked. Thanks a lot.

@hvkktr,
I’m glad your issue has been solved. If you have any questions, please feel free to contact us.

1 Like