使用 Printer 对象
有几种方法可在 Printer 对象中放置文本和图形。为了使用 Printer 对象进行打印,应按以下任一方式进行: 如果要使用缺省打印机以外的打印机打印,需在 Printers 集合中指定打印机给 Printer 对象。
将文本和图形装入 Printer 对象。
用 NewPage 和 EndDoc 方法打印 Printer 对象的内容。 
Printer 对象的属性
Printer 对象的属性,初始化时与 Windows“控制面板”中设置的缺省打印机的那些属性匹配。运行时,可设置任何 Printer 对象的属性,包括:PaperSize,Height,Width,Orientation,ColorMode,Duplex,TrackDefault,Zoom,DriverName,DeviceName,Port,Copies,PaperBin 和 PrintQuality。关于这些方法的细节和语法,请参阅《语言参考》。如果 TrackDefault 属性为 True,并且在 Windows“控制面板”中改变了缺省打印机,则 Printer 对象属性值将会反映新的缺省打印机的属性。在一页当中,一旦设置了某个属性,就不能在该页中改变某些属性。对这些属性的改变只能影响以后各页。下列语句给出了如何用不同的打印质量来打印各页:For pageno = 1 To 4
   Printer.PrintQuality = -1 * pageno
   Printer.Print "The quality of this page is"; pageno
   Printer.NewPage
Next打印质量值可从 –4 到 –1,或是一个与打印机分辨率(每英寸的点数 DPI)对应的正整数。例如,下列代码把打印机分辨率设置为 300 DPI:Printer.PrintQuality = 300详细信息 关于 Printer 对象属性的详细信息,请参阅《语言参考》的有关属性的内容。注意 Printer 属性值的效果依赖于打印机生产厂家提供的驱动程序。有些属性设置值没有作用,或几个不同的属性设置值可能有相同作用。在允许值范围之外的设置,可能产生错误,也可能不会产生错误。关于指定驱动程序的详细信息,请参阅生产厂家的文档资料。Scale 属性
Printer 对象有以下刻度属性: ScaleMode
ScaleLeft 和 ScaleTop
ScaleWidth 和 ScaleHeight
Zoom 
TScaleLeft 和 ScaleTop 属性分别定义打印页左上角的 x 坐标和 y 坐标。通过改变 ScaleLeft 和 ScaleTop 的值,可改变打印页的左边距和上边距。例如,通过下列语句,用 ScaleLe 和 ScaleTop 可指定打印的窗体 (PFrm) 在页中心:Printer.ScaleLeft = -((Printer.Width - PFrm.Width) / 2)
Printer.ScaleTop = -((Printer.Height - PFrm.Height) _
   / 2)许多打印机都支持 Zoom 属性。该属性定义按原来的百分之多少输出。缺省的 Zoom 属性值为 100,指定输出将按实际尺寸的百分之百来打印。可利用 Zoom 属性使打印页比实际纸页大一些或小一些。例如,将 Zoom 属性设置为 50,可使打印页看起来只是实际打印纸页长和宽的一半。下列语法将缺省 Printer 对象的 Zoom 属性设置为原来的一半:Printer.Zoom = 50定位文本和图形
就象为窗体和图形框设置属性一样,可为 Printer 对象设置 CurrentX 和 CurrentY 属性。这两个属性决定 Printer 对象当前页中的输出位置。下列语句设置了当前页左上角的图片坐标:Printer.CurrentX = 0
Printer.CurrentY = 0也可用 TextHeight 和 TextWidt 方法在 Printer 对象中定位文本。关于使用这些文本方法的详细内容,请参阅本章前面的“在指定位置显示打印输出”一节。在 Printer 对象上打印窗体
也许需要应用程序打印一个或多个窗体(连同窗体上的信息),尤其是当窗体的设计用于发票或时间表之类的打印资料时,更是如此。要做到这一点,最简单的途径是用 PrintForm 方法。在 Printer 对象中使用 Print 和图形方法,可在激光打印机上获得最佳效果。但要注意,使用 Printer 对象之前需要做较多准备,因为在打印之前要在 Printer 对象中重建窗体。在 Printer 对象中重建窗体也可能需要重建下列内容: 窗体的轮廓,包括标题和菜单栏。
控件和它们的内容,包括文本和图形。
直接应用于窗体的图形输出方法,包括 Print方法。 
重建 Printer 对象中的元素的扩展工作,取决于应用程序和所需打印窗体内容的多少。在窗体上重建文本和图形
当使用 Print,Line,Circle,PaintPicture 或 PSet 方法,在窗体中创建文本和图形时,可能需要在 Printer 对象中显示一个输出备份。实现此操作的最简便方法就是遍写一个与设备无关的过程来重建文本和图形。例如,下列过程就使用了 PaintPicture 方法,将窗体或控件的 Picture 属性打印到任意一个输出对象中,如,打印机或另一个窗体:Sub PrintAnywhere (Src As Object, Dest As Object)
   Dest.PaintPicture Src.Picture, Dest.Width / 2, _
      Dest.Height / 2
   If Dest Is Printer Then 
      Printer.EndDoc
   End If
End Sub然后调用此过程,并传送原对象和目标对象:PrintAnywhere MyForm, Printer
PrintAnywhere MyForm, YourForm详细信息 详细信息请参阅《语言参考》的“Print 方法”,“Line 方法”,“Circle 方法”,“Pset 方法”或“PaintPicture 方法”。打印窗体上的控件
Printer 对象可接收 Print 方法和图形方法的输出(如:Line 方法或 Pset 方法)。但不能把控件直接放在 Printer 对象中。如果应用程序需要打印控件,则必须编写过程来调用 Printer 对象要用到的每种控件,或使用 PrintForm 方法。打印 Printer 对象的内容
一旦将文本和图形放到 Printer 对象中,就可用 EndDoc 方法打印该内容。EndDoc 方法要换页,并将悬置的所有输出都送给假脱机系统。spooler 在输出传送到打印机的过程中,截取打印作业,并将它送往硬盘或内存,将打印工作保存在那里,直到打印机准备好为止。例如:Printer.Print "This is the first line of text in _
   a pair."
Printer.Print "This is the second line of text in _
   a pair."
Printer.EndDoc注意 如果应用程序结尾没有明确调用 EndDoc,Visual Basic 会自动调用。创建多页文档
打印较长的文档时,可用 NewPage 方法,在代码中指定新的一页。例如:Printer.Print "This is page 1."
Printer.NewPage
Printer.Print "This is page 2."
Printer.EndDoc取消打印作业
可用 KillDoc 方法结束当前的打印作业。例如,可用对话框询问是继续打印还是结束文档:Sub PrintOrNot()
   Printer.Print "This is the first line to _
      illustrate KillDoc method"
   Printer.Print "This is the second line to _
      illustrate KillDoc method"
   Printer.Print "This is the third line to _
      illustrate KillDoc method"
   If vbNo = MsgBox("Print this fine document?", _
         vbYesNo) Then
      Printer.KillDoc
   Else
      Printer.EndDoc
   End If
End Sub如果操作系统的打印管理器正在处理打印工作,则 KillDoc 方法将删除送入打印机的所有作业。但如果打印管理器没有控制打印工作,可能有页已送入打印机并且不会受 KillDoc 的影响。送入打印机的数据量与打印机驱动程序中的数据量稍有不同。注意 使用 KillDoc 方法不能结束使用 PrintForm 方法开始打印的作业。

解决方案 »

  1.   

    Private Sub printsub(x As Integer, y As Variant, quhao As Variant, guige1 As Variant, guige2 As Variant, xilie As Variant, pinming As Variant, huahao As Variant, riqi As Variant, dabao As Variant, tuobei As Variant)
        Printer.FontName = "黑体"
        Printer.FontBold = True
        Printer.CurrentX = (x + 3.5) * 567
        Printer.CurrentY = (y + 1) * 567
        Printer.FontSize = 72
        Printer.Print quhao
        
        Printer.CurrentX = (x + 1.2) * 567
        Printer.CurrentY = (y + 3) * 567
        Printer.FontSize = 100
        If tuobei = 2 Or tuobei = 4 Or tuobei = 5 Then
            Printer.Print guige1;
            Printer.CurrentY = (y + 3.5) * 567
            Printer.FontSize = 64
            Printer.Print " "; guige2
        Else
            Printer.Print guige1; "X"; guige2
        End If
        
        
        Printer.CurrentX = (x + 1.2) * 567
        Printer.CurrentY = (y + 6.5) * 567
        Printer.FontSize = 40
        If tuobei = 0 Then
        'Picture1.FontSize = 45
            Printer.Print xilie; "("; pinming; ")"
        ElseIf tuobei = 1 Then
            Printer.Print xilie; "("; pinming; "皮托"; ")"
        ElseIf tuobei = 2 Then
            Printer.Print xilie; "("; pinming; "皮背"; ")"
        ElseIf tuobei = 3 Then
            Printer.Print xilie; "("; pinming; "布托"; ")"
        ElseIf tuobei = 4 Then
            Printer.Print xilie; "("; pinming; "布背"; ")"
        ElseIf tuobei = 5 Then
            Printer.Print xilie; "("; pinming; "圆床"; ")"
        End If
        
        
        
        
        Printer.CurrentX = (x + 2) * 567
        Printer.CurrentY = (y + 8) * 567
        'Printer.FontSize = 38
        Printer.Print huahao; " "; riqi
        
        If dabao = "1" Then
            Printer.CurrentX = (x + 2) * 567
            Printer.CurrentY = (y + 1.5) * 567
            Printer.PaintPicture bm, Printer.CurrentX, Printer.CurrentY, 600, 800
        End If
    End Sub给你段代码
      

  2.   

    在工程->引用里添加"Microsoft Excel Object"Private Sub Command1_Click()
    Dim exlApp As New Excel.Application
    Dim wb As Workbook
    Dim ws As WorksheetexlApp.Visible = True
    Set wb = exlApp.Workbooks.Add
    Set ws = wb.ActiveSheet
    ws.Cells(1, 1) = "Hello,Excel"
    wb.SaveAs "c:\t.xls"
    exlapp.printout
    exlApp.Quit
    Set exlApp = noting
    End Sub
      

  3.   

    如果机子没有安装Excel,能否调用excel??
      

  4.   

    试试OrchidPrinter
    download from www.orient-orchid.com
      

  5.   

    用ActiveReport打印吧,预览起来非常方便
      

  6.   

    直接写口打印也行
    把LPT1当作一个文件!
      

  7.   

    why not use vsflexgrid & vsview?
      

  8.   

    HTTP://ygyuan.go.163.com/
    http://ygyuan.3322.net/可预览的 Printer 对像,袁飞打印预览控件.
      

  9.   

    HTTP://ygyuan.go.163.com/
    http://ygyuan.3322.net/可预览的 Printer 对像,袁飞打印预览控件.
      

  10.   

    HTTP://ygyuan.go.163.com/
    http://ygyuan.3322.net/可预览的 Printer 对像,袁飞打印预览控件.