I am using epplus with this code to set the printer options in the target excel file:
ExcelWorksheet ew; ew.PrinterSettings.TopMargin = tartetTopMarginValueInCm / 2.54M; ew.PrinterSettings.RightMargin = targetRightMarginValueInCm / 2.54M; ... ew.PrinterSettings.HeaderMargin = targetHeaderMarginInCm / 2.54M;
Remember to convert cm to inch (if you want to use cm because all epplus printer settings are in inches).
Screen with Page Setup in Excel and Printer Settings in Epplus:

source share