Hi,
Thank you for your inquiry.
Yes, you can set the top margin by calculating the height of the header content. Please refer to the following code. If there is any problem, please provide your sample excel file for our reference. You could attach it here or send to us via email (
support@e-iceblue.com). Thanks in advance.
In addition, you are using the .NetCore platform, I suggest that you download the latest package
Spire.Office.NETCore 6.8.2 in NuGet manager.
- Code: Select all
Workbook workbook = new Workbook();
workbook.LoadFromStream(stream);
PageSetup setup = workbook.Worksheets[0].PageSetup;
setup.IsFitToPage = true;
setup.FitToPagesTall = 1;
setup.FitToPagesWide = 1;
string CenterHeaderStr = "&\"Arial\"&B&16&K800000&UDEMO\nDemo诊所\nDEMO\n預設醫生";
setup.CenterHeader = CenterHeaderStr;
Font font = new Font(new FontFamily("Arial"),16,FontStyle.Underline);
//Gets the font line spacing
float height = font.Height * 4;
double herders = setup.HeaderMarginInch;
//Convert the font pixel to the page margin inch
PdfUnitConvertor convertor = new PdfUnitConvertor();
float heighInInch =convertor.ConvertUnits(height, PdfGraphicsUnit.Pixel, PdfGraphicsUnit.Inch);
//Set the margins
setup.TopMargin = heighInInch + herders;
workbook.Worksheets[0].ViewMode = ViewMode.Layout;
workbook.SaveToFile("1.xlsx");
Sincerely,
Annika
E-iceblue support team