You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用VB.NET禁用SAP Crystal Reports打印预览 直接打印到默认打印机

无预览直接打印小票实现方案

你可以直接调用Crystal Reports中ReportDocument对象的PrintToPrinter方法,跳过预览窗口直接将打印任务发送到系统默认打印机,替换原有触发预览的代码即可。

修改后代码

Private Sub BTPRINT_Click(sender As Object, e As EventArgs) Handles BTPRINT.Click
    Dim dt As New DataTable
    With dt
        .Columns.Add("Articulo")
        .Columns.Add("Cantidad")
        .Columns.Add("Precio")
    End With
    For Each dgr As DataGridViewRow In Me.DataGridView1.Rows
        dt.Rows.Add(dgr.Cells(0).Value, dgr.Cells(1).Value, dgr.Cells(2).Value)
    Next

    Dim reportdocument As CrystalDecisions.CrystalReports.Engine.ReportDocument
    reportdocument = New CrystalReport2
    reportdocument.SetDataSource(dt)
    
    ' 跳过预览直接打印到默认打印机,参数可按需调整
    reportdocument.PrintToPrinter(1, False, 0, 0)
    
    ' 释放报表资源
    reportdocument.Close()
    reportdocument.Dispose()
End Sub

参数说明

PrintToPrinter方法4个传入参数含义如下:

  • 第1位:打印份数,为整数类型,示例中1代表打印1份
  • 第2位:是否逐份打印,为布尔类型,单份打印时可设为False
  • 第3位:打印起始页码,设为0代表无起始页限制,从第一页开始打印
  • 第4位:打印结束页码,设为0代表打印报表全部页面

注意事项

  • 提前在CrystalReport2的设计界面配置好对应小票的纸张尺寸、边距参数,避免打印内容错位
  • 确保运行程序的设备默认打印机配置正常,程序拥有打印机访问权限
  • 如需指定非默认打印机打印,可先通过reportdocument.PrintOptions.PrinterName设置目标打印机名称,再调用打印方法

内容的提问来源于stack exchange,提问作者jumexmango

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.03 16:24:00