海波.NET
问题:
直接打印报表,不预览、不设置打印机,怎么做?
在程序中有做完的报表.RPT,我想按一个按钮就直接打印,不预览、不设置打印机,怎么做?
——————————————————————————————————————
解决方案:
ReportDocument.PrintToPrinter 方法要求
命名空间:CrystalDecisions.CrystalReports.Engine 
平台:Windows 98,Windows NT 4.0,Windows Millennium Edition,Windows 2000
程序集:CrystalDecisions.CrystalReports.Engine使用 PrintOptions.PrinterName 属性将报表的指定页输出到选定的打印机上。如果未选择打印机,则将使用报表中指定的默认打印机。[Visual Basic] 
Public Overridable Sub PrintToPrinter(ByVal nCopies As Integer, ByVal collated As Boolean, ByVal startPageN As Integer, ByVal endPageN As Integer)
[C#] 
public virtual void PrintToPrinter (int nCopies , bool collated , int startPageN , int endPageN );
[C++] 
public virtual void PrintToPrinter (int nCopies , bool collated , int startPageN , int endPageN );参数
nCopies 
指明要打印的份数。 
collated 
指明是否逐份打印。 
startPageN 
指明要打印的第一页。 
endPageN 
指明要打印的最后一页。 
备注
若要打印所有页,请将 startPageN 参数和 endPageN 参数设置为零。 示例
下面的示例设置报表的页边距,选择打印机,并打印报表。
[Visual Basic] 
Private Sub PrintReport(ByVal printerName As String)
   Dim margins As PageMargins   ' 获取 PageMargins 结构并设置
   ' 报表边距。
   margins = Report.PrintOptions.PageMargins
   margins.bottomMargin = 350
   margins.leftMargin = 350
   margins.rightMargin = 350
   margins.topMargin = 350
   ' 应用页边距。
   Report.PrintOptions.ApplyPageMargins(margins)   ' 选择打印机。
   Report.PrintOptions.PrinterName = printerName' 打印报表。将 startPageN 和 endPageN
   '参数设置为 0 表示打印所有页。
   Report.PrintToPrinter(1, False, 0, 0)
End Sub
[C#] 
private void PrintReport(string printerName)
{
   PageMargins margins;   // 获取 PageMargins 结构并设置
   //报表的边距。
   margins = Report.PrintOptions.PageMargins;
   margins.bottomMargin = 350;
   margins.leftMargin = 350;
   margins.rightMargin = 350;
   margins.topMargin = 350;
   // 应用页边距。
   Report.PrintOptions.ApplyPageMargins(margins);   // 选择打印机。
   Report.PrintOptions.PrinterName = printerName;   // 打印报表。将 startPageN 和 endPageN 
   // 参数设置为 0 表示打印所有页。
   Report.PrintToPrinter(1, false,0,0);
}
[C++] 
void PrintReport(String* printerName)
{
   PageMargins margins;   // 获取 PageMargins 结构并设置
   //报表的边距。
   margins = Report->PrintOptions->PageMargins;
   margins.bottomMargin = 350;
   margins.leftMargin = 350;
   margins.rightMargin = 350;
   margins.topMargin = 350;
   // 应用页边距。
   Report->PrintOptions->ApplyPageMargins(margins);   // 选择打印机。
   Report->PrintOptions->PrinterName = printerName;   // 打印报表。将 startPageN 和 endPageN 
   // 参数设置为 0 表示打印所有页。
   Report->PrintToPrinter(1, false,0,0);
};
——————————————————————————————————————
PrintOptions 类  [C#]
要求
命名空间:CrystalDecisions.CrystalReports.Engine 
平台:Windows 98,Windows NT 4.0,Windows Millennium Edition,Windows 2000
程序集:CrystalDecisions.CrystalReports.Engine提供用于设置报表打印选项的属性和方法。
有关该类型所有成员的列表,请参见 PrintOptions 成员。Object
   PrintOptions
[Visual Basic] 
Public Class PrintOptions
[C#] 
public class PrintOptions
[C++] 
__gc public class PrintOptions
备注
通过ReportDocument对象的PrintOptions 属性来检索 PrintOptions 对象。

解决方案 »

  1.   

    海波.NET
    问题:
    如何在水晶报表中控制每页的行数啊(比如每页20条记录)???
    ——————————————————————————————————————
    解决方案一
    1、右键单击“详细资料”节的灰色横条,选择“节专家”,进入“节专家”对话框;
    2、在“公用”选项卡,选中“在后面页新建页”复选框;
    3、单击后面的“x+2”按钮,进入“公式工作室 - 格式公式编辑器”对话框;
    4、输入“RecordNumber mod 20 = 0”,并单击左上角的“保存并关闭”按钮。
    注意:是 Crystal Report 语法。