Try ( TRIED AND TESTED )
I assume you have set the Excel link and already declared your objects as
Microsoft.Office.Interop.Excel.Application xlexcel;
Microsoft.Office.Interop.Excel.Workbook xlWorkBook;
Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet;
Microsoft.Office.Interop.Excel.Range xlRange;
object misValue = System.Reflection.Missing.Value;
This applies to the later part of the code.
string Defprinter = null;
Defprinter = xlexcel.ActivePrinter;
xlexcel.ActivePrinter = "Microsoft XPS Document Writer on Ne01:";
var _with1 = xlWorkSheet.PageSetup;
_with1.PaperSize = Excel.XlPaperSize.xlPaperA4;
_with1.Orientation = Excel.XlPageOrientation.xlLandscape;
_with1.FitToPagesWide = 1;
_with1.FitToPagesTall = 1;
_with1.LeftMargin = xlexcel.InchesToPoints(0.7);
_with1.RightMargin = xlexcel.InchesToPoints(0.7);
_with1.TopMargin = xlexcel.InchesToPoints(0.75);
_with1.BottomMargin = xlexcel.InchesToPoints(0.75);
_with1.HeaderMargin = xlexcel.InchesToPoints(0.3);
_with1.FooterMargin = xlexcel.InchesToPoints(0.3);
xlRange.PrintOutEx(misValue, misValue, misValue, misValue,
misValue, misValue, misValue, misValue);
xlexcel.ActivePrinter = Defprinter;
source
share