c# - Excel Interop Print -


i need print selected area of excel sheet (which selected range.select()) using following print settings:

printer: microsoft xps document writer
print selection
landscape orientation
a4
normal margins
fit sheet on 1 page

how can achieve using _worksheet.printout or _worksheet.printoutex?

thanks in advance!

try (tried , tested)

i assuming have set reference excel , have declared objects

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 goes in later part of code.

// current printer string defprinter = null; defprinter = xlexcel.activeprinter;  // set printer microsoft xps document writer xlexcel.activeprinter = "microsoft xps document writer on ne01:";  // setup our sheet var _with1 = xlworksheet.pagesetup; // a4 papersize _with1.papersize = excel.xlpapersize.xlpapera4; // landscape orientation _with1.orientation = excel.xlpageorientation.xllandscape; // fit sheet on 1 page  _with1.fittopageswide = 1; _with1.fittopagestall = 1; // normal margins _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);  // print range xlrange.printoutex(misvalue, misvalue, misvalue, misvalue,  misvalue, misvalue, misvalue, misvalue);  // set printer xlexcel.activeprinter = defprinter; 

Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -