public void SetPrinterSettings(ExcelPrinterSettings excelPrinterSettings) { if (excelPrinterSettings.PageMargins != null) { var pageMargins = worksheet.Elements <PageMargins>().FirstOrDefault() ?? new PageMargins(); pageMargins.Left = excelPrinterSettings.PageMargins.Left; pageMargins.Right = excelPrinterSettings.PageMargins.Right; pageMargins.Top = excelPrinterSettings.PageMargins.Top; pageMargins.Bottom = excelPrinterSettings.PageMargins.Bottom; pageMargins.Header = excelPrinterSettings.PageMargins.Header; pageMargins.Footer = excelPrinterSettings.PageMargins.Footer; if (!worksheet.Elements <PageMargins>().Any()) { InsertWorksheetChild(worksheet, pageMargins); } } var pageSetup = worksheet.Elements <PageSetup>().FirstOrDefault() ?? new PageSetup(); pageSetup.Orientation = excelPrinterSettings.PrintingOrientation == ExcelPrintingOrientation.Landscape ? OrientationValues.Landscape : OrientationValues.Portrait; if (!worksheet.Elements <PageSetup>().Any()) { InsertWorksheetChild(worksheet, pageSetup); } }
private static void SetMargins(ExcelPrinterSettings printerSettings, ExportOptions options) { printerSettings.BottomMargin = ConvertToPrintUnit(options.Margins.Bottom); printerSettings.TopMargin = ConvertToPrintUnit(options.Margins.Top); printerSettings.LeftMargin = ConvertToPrintUnit(options.Margins.Left); printerSettings.RightMargin = ConvertToPrintUnit(options.Margins.Right); }
/// <summary> /// Sets the margins of document from model. /// </summary> /// <param name="settings">The settings.</param> /// <param name="margins">The margins.</param> /// <returns> /// An <see cref="ExcelPrinterSettings"/> reference which contains the margins values. /// </returns> public static ExcelPrinterSettings SetMarginsFromModel(this ExcelPrinterSettings settings, XlsxDocumentMargins margins) { SentinelHelper.ArgumentNull(settings, nameof(settings)); SentinelHelper.ArgumentNull(margins, nameof(margins)); var units = margins.Units; if (units == KnownUnit.Millimeters) { settings.TopMargin = (decimal)margins.Top * 0.039370m; settings.LeftMargin = (decimal)margins.Left * 0.039370m; settings.RightMargin = (decimal)margins.Right * 0.039370m; settings.BottomMargin = (decimal)margins.Bottom * 0.039370m; } else { settings.TopMargin = (decimal)margins.Top; settings.LeftMargin = (decimal)margins.Left; settings.RightMargin = (decimal)margins.Right; settings.BottomMargin = (decimal)margins.Bottom; } return(settings); }