您的位置:首页 > 编程语言 > C#

C#打印DataGrid中的数据[转贴]

2006-04-20 13:35 288 查看
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();}

C#打印DataGrid中的数据[转贴]

document.title="C#打印DataGrid中的数据[转贴] - "+document.title


对于信息系统,打印功能是必须的。而打印,是一件相当麻烦的事情。打印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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: