प्रयास करें इस (कोशिश की और परीक्षण)
मैं यह सोचते हैं रहा हूँ आप Excel के संदर्भ में निर्धारित किया है और पहले से ही
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;
इस कोड के बाद के हिस्से में चला जाता है की तरह अपने वस्तुओं घोषणा की है कि ।
// Get the current printer
string Defprinter = null;
Defprinter = xlexcel.ActivePrinter;
// Set the printer to 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 One 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 the range
xlRange.PrintOutEx(misValue, misValue, misValue, misValue,
misValue, misValue, misValue, misValue);
// Set printer back to what it was
xlexcel.ActivePrinter = Defprinter;
स्रोत
2012-06-05 16:52:27
आपको बहुत बहुत धन्यवाद! लेकिन आप "Ne01 पर" कैसे जानते थे? – MemphiZ
आप 'Defprinter = xlexcel.ActivePrinter;' का उपयोग करके पा सकते हैं और फिर इसे तत्काल विंडो में प्रिंट कर सकते हैं। वह कोड आपको बताएगा कि आपका सक्रिय प्रिंटर क्या है। इसका परीक्षण करने के लिए प्रिंटर को एक्सपीएस में बदलें और फिर उपरोक्त कोड चलाएं। –
मुझे यह पता लगाने के लिए कि किस पोर्ट का उपयोग करना है: http://stackoverflow.com/questions/5424932/how-to-determine-what-ne-port-the-adobe-pdf-printer-is-on। पेजसेटअप के अलावा FitToPagesWide/Tall कार्य करने और श्रेणी का उपयोग करने के लिए झूठी पर सेट किया जाना चाहिए। एक्सपोर्टएक्सफिक्स्डफॉर्मैट (XlFixedFormatType.xlTypeXPS, outputPath); PrintOutEx के बजाय। हो सकता है कि आप उपरोक्त अपना कोड अपडेट कर सकें :) – MemphiZ