2012-06-05 15 views
5

मैं एक एक्सेल शीट की एक चयनित क्षेत्र (जो मैं Range.Select() के साथ चयनित) मुद्रित करने के लिए निम्न प्रिंट सेटिंग्स का उपयोग कर की जरूरत है लैंडस्केप अभिविन्यास
ए 4
सामान्य मार्जिन
एक पृष्ठ पर फिट शीटएक्सेल इंटरॉप प्रिंट

मैं इस _Worksheet.PrintOut या _Worksheet.PrintOutEx का उपयोग कर प्राप्त कर सकते हैं?

अग्रिम धन्यवाद!

उत्तर

13

प्रयास करें इस (कोशिश की और परीक्षण)

मैं यह सोचते हैं रहा हूँ आप 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; 
+0

आपको बहुत बहुत धन्यवाद! लेकिन आप "Ne01 पर" कैसे जानते थे? – MemphiZ

+2

आप 'Defprinter = xlexcel.ActivePrinter;' का उपयोग करके पा सकते हैं और फिर इसे तत्काल विंडो में प्रिंट कर सकते हैं। वह कोड आपको बताएगा कि आपका सक्रिय प्रिंटर क्या है। इसका परीक्षण करने के लिए प्रिंटर को एक्सपीएस में बदलें और फिर उपरोक्त कोड चलाएं। –

+1

मुझे यह पता लगाने के लिए कि किस पोर्ट का उपयोग करना है: http://stackoverflow.com/questions/5424932/how-to-determine-what-ne-port-the-adobe-pdf-printer-is-on। पेजसेटअप के अलावा FitToPagesWide/Tall कार्य करने और श्रेणी का उपयोग करने के लिए झूठी पर सेट किया जाना चाहिए। एक्सपोर्टएक्सफिक्स्डफॉर्मैट (XlFixedFormatType.xlTypeXPS, outputPath); PrintOutEx के बजाय। हो सकता है कि आप उपरोक्त अपना कोड अपडेट कर सकें :) – MemphiZ

0

'काम पर फ़िट शीट' के लिए हमें ज़ूम संपत्ति को झूठी पर सेट करना चाहिए।

// एक पृष्ठ पर फिट शीट

_with1.FitToPagesWide = 1; 

_with1.FitToPagesTall = 1; 

_with1.Zoom = False; 
संबंधित मुद्दे