水晶報表列印知識—編程式控制制列印

來源:互聯網
上載者:User

(引自http://blog.csdn.net/xwdd129/archive/2006/06/01/768033.aspx)
水晶報表檢視器CrystalReportViewer內建列印功能,調用當前系統預設印表機進行列印,但.NET裡的水晶版本不支援Web列印,需要水晶報表10以上的版本才支援。另外由於其他原因,我們大多需要自己寫代碼進行列印,這就牽扯到如何寫代碼、如何設定列印參數的問題,以下是一些基本知識:

列印的基本代碼:

CrystalReport1 report = new CrystalReport1(); //Report為你自己的報表名
PageMargins margins;
margins = Report.PrintOptions.PageMargins;
margins.bottomMargin = 250;
margins.leftMargin = 350;
margins.rightMargin = 350;
margins.topMargin = 350;
// Apply the page margins.
Report.PrintOptions.ApplyPageMargins(margins);

// Select the printer.
string printerName = "\\\\區域網路機器名\\印表機名(例如HP 2100)";  //本機印表機直接指定名稱
Report.PrintOptions.PrinterName = printerName;          //指定印表機名稱
Report.PrintOptions.PaperSize = PaperSize.PaperA4;   //指定紙張尺寸

report.PrintToPrinter(1, true, 1, 4);

下面簡單就列印中的參數進行說明:

PrintOptions類,提供用於設定報表列印選項的屬性和方法。

PrintOptions成員:
    PageContentHeight---Int32,擷取頁面內容的高度
    PageContentWidth---Int32,擷取頁面內容的寬度
    PageMargins---擷取報表的邊距
    PageOrientation---擷取或設定印表機紙張方向
    Pagesize---擷取或設定當前印表機紙張的大小
    PrinterName---字串,擷取或設定報表所使用的印表機名稱

ReportDocument.PrintToPrinter方法
public virtual void PrintToPrinter( int nCopies, bool collated, int startPageN, int endPageN )
    nCopies 指明要列印的分數
    collated 指明是否逐份列印
    startPageN 指明要列印的第一頁
    endPageN 指明要列印的最後一頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.