C#打印DataGrid中的數據[轉貼]

<script type="text/javascript"> function StorePage(){d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(keyit=window.open('http://www.365key.com/storeit.aspx?t='+escape(d.title)+'&u='+escape(d.location.href)+'&c='+escape(t),'keyit','scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes'));keyit.focus();} </script>  C#打印DataGrid中的數據[轉貼] <script language="JavaScript" type="text/javascript"> document.title="C#打印DataGrid中的數據[轉貼] - "+document.title </script>

對於信息系統,打印功能是必須的。而打印,是一件相當麻煩的事情。打印DataGrid中的數據,尤其如此。要想到的很多,包括頁眉、頁腳設置,打印字體,分頁,標題,預覽等等一系列問題。如果從頭寫,工作量實在太大。網絡上有很多C#寫的打印DataGrid類代碼,我幾乎挨個嘗試了個遍,要麼就是不能正常使用,要麼就是丟失數據,最後在打算自己寫一個簡單的時候,突然想起了機器上安裝的Developer.Express.NET.Windows.Forms.Components.Suite控件。到工具欄裏一看,果然有幾個打印控件。再找些該控件的相關資料,很容易就搞定了打印DataGrid的功能。下面是兩個函數,一個是直接打印,一個是打印預覽。實現的效果非常的好。

public void Print(DataGrid dataGrid1)

{

     DevExpress.XtraPrinting.PrintingSystem ps=new DevExpress.XtraPrinting.PrintingSystem();

     DevExpress.XtraPrintingLinks.DataGridLink printlink=new DevExpress.XtraPrintingLinks.DataGridLink();

     System.Windows.Forms.Cursor currentCursor=Cursor.Current;

     Cursor.Current=System.Windows.Forms.Cursors.WaitCursor;

     printlink.DataGrid=dataGrid1;

     printlink.CreateDocument(ps);

     ps.PrintDlg();

}

 public void PrintReview(DataGrid dataGrid1)

{

     DevExpress.XtraPrinting.PrintingSystem ps=new DevExpress.XtraPrinting.PrintingSystem();

     DevExpress.XtraPrintingLinks.DataGridLink printlink=new DevExpress.XtraPrintingLinks.DataGridLink();

     System.Windows.Forms.Cursor currentCursor=Cursor.Current;

     Cursor.Current=System.Windows.Forms.Cursors.WaitCursor;

     printlink.DataGrid=dataGrid1;

     printlink.CreateDocument(ps);

     ps.PreviewForm.Show();

     Cursor.Current=currentCursor;

}

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章