We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to know the header height?

Hi to all, I want to insert a customer logo in a worksheet header. Is there a way to automatic resize the image to the headre height? if not, it is possible to know the header heigth?

Thank you in advance.


1 Reply

MN Meikanda Nayanar Syncfusion Team April 11, 2019 08:25 AM

Hi Federico, 
The header height can’t be modified in Microsoft Excel, Syncfusion Excel library (XlsIO) does the same. However, we can modify the top/bottom and header/footer margin based on the image height to fit the image in the header. 
We have prepared the sample in which header has been changed based on image height and using header and top margin. The sample can be downloaded from the below link. 
Sample Link: 
Code snippet: 
              Image image = Image.FromFile(@"../../logo.png"); 
              //Getting the image height in inches 
              double heightInInches = image.Size.Height /(image.VerticalResolution); 
              //Set the pagesetup top margin to image height to fit 
              worksheet.PageSetup.TopMargin = heightInInches; 
              //Set the pagesetup header margin is 0 
              worksheet.PageSetup.HeaderMargin = 0; 
              //Set the image in header 
              worksheet.PageSetup.CenterHeader = "&G"; 
              worksheet.PageSetup.CenterHeaderImage = image; 
Please let us know if you have any clarifications. 

Live Chat Icon For mobile
Up arrow icon