XtraReports 打印控件的简单使用

今天有人问我DEV打印控件 的使用,刚好自己好长时间没有编码了,所以写了一个简单的DataTale打印练习,希望时间长了以后看到这片文章以后能熟悉
1)建立工程文件
2)在工程里面添加新项,名称XtraReport2.cs

3) 在打印调用主界面 引用
using DevExpress.XtraReports.UI;
using  DevExpress.XtraPrinting.Localization ;
4)填充数据,代码如下:

        
private void simpleButton1_Click(object sender, System.EventArgs e)
        
{

            XtraReport1  xrpt1
=new XtraReport1(GetTempDataSet(),"单位","标题");
            PreviewLocalizer.Active 
= new ChineaseReportLocalizer();
            xrpt1.ShowPreviewDialog();
        }

        
private DataSet GetTempDataSet()
        
{
            DataSet ds
=new DataSet();
            DataTable dt
=new DataTable("tempTable");
            dt.Columns.Add(
"Col1",Type.GetType("System.String"));
            dt.Columns.Add(
"Col2",Type.GetType("System.String"));
            dt.Columns.Add(
"Col3",Type.GetType("System.String"));
            dt.Columns.Add(
"Col4",Type.GetType("System.String"));
            dt.Columns.Add(
"Col5",Type.GetType("System.String"));
            dt.Columns.Add(
"Col6",Type.GetType("System.String"));
            dt.Columns.Add(
"Col7",Type.GetType("System.String"));
            DataRow tempRow;              
            
for (int i=0;i<7;i++)//i:Row
            {
                tempRow
=dt.NewRow();
                tempRow[
0]=i.ToString();
                tempRow[
1]=i.ToString();
                tempRow[
2]=i.ToString();
                tempRow[
3]=i.ToString();
                tempRow[
4]=i.ToString();
                tempRow[
5]=i.ToString();
                tempRow[
6]=i.ToString();
                dt.Rows.Add(tempRow);
            }


            ds.Tables.Add(dt);
            
return ds;


        }

这个里面 simpleButton1_Click 是打印 键的click事件
5)在XtraReport1.cs 里面的图形界面里面进行属性的相关设置,和增加相关的打印控件,具体操作如下图:

6)增加相关代码:
    public XtraReport1(DataSet dset,string unitName,string title)//构造函数重载
        {
            InitializeComponent();
            SetDataBind(dset,unitName,title);
        }

        
private void SetDataBind(DataSet dataset,string unitname,string title)
        
{
            DataSource
=dataset;   
            
this.xrTableCell3.Text=unitname;
            
this.xrTableCell9.Text=title;
            
this.xrTableCell4.DataBindings.Add("Text", DataSource, "Col1");
            
this.xrTableCell5.DataBindings.Add("Text", DataSource, "Col2");
        }

7)注意有一个本地化类 ChineaseReportLocalizer
using System;

using System.Data;
using  DevExpress.XtraPrinting.Localization ; 
using DevExpress.XtraEditors.ViewInfo;
namespace ReportView
{
    
public class ChineaseReportLocalizer : DevExpress.XtraPrinting.Localization.PreviewLocalizer
    
{

        
public override string Language get return "简体中文"; }}
        
public override string GetLocalizedString(PreviewStringId id) 
        
{
            
string ret = "";
            
switch(id) 
            
{
                
case  PreviewStringId.PreviewForm_Caption : return "统计报表预览";
                
case  PreviewStringId.MenuItem_File : return "文件";
                
case  PreviewStringId.MenuItem_PageSetup : return "页面设置";
                
case  PreviewStringId.MenuItem_PrintDirect : return "打印设置";
                
case  PreviewStringId.MenuItem_Print : return "打印";
                
case  PreviewStringId.MenuItem_Export : return "导出";
                
case  PreviewStringId.MenuItem_PdfDocument : return "Pdf文档";
                
case  PreviewStringId.MenuItem_RtfDocument : return "Rtf文档";
                
case  PreviewStringId.MenuItem_TxtDocument : return "Txt文档";
                
case  PreviewStringId.MenuItem_XlsDocument : return "Xls文档";
                
case  PreviewStringId.MenuItem_HtmDocument : return "Htm文档";
                
case  PreviewStringId.MenuItem_GraphicDocument : return "Graphic文档";
                
case  PreviewStringId.MenuItem_CsvDocument : return "Csv文档";
                
case  PreviewStringId.MenuItem_MhtDocument : return "Mht文档";
                
case  PreviewStringId.MenuItem_Send : return "发送";
                
case  PreviewStringId.MenuItem_Exit : return "退出";

                
case  PreviewStringId.MenuItem_View : return "查看";
                
case  PreviewStringId.MenuItem_ViewToolbar : return "工具栏";
                
case  PreviewStringId.MenuItem_ViewStatusbar : return "状态条";

                
case  PreviewStringId.MenuItem_Background : return "背景";
                
case  PreviewStringId.MenuItem_BackgrColor : return "颜色";
                
case  PreviewStringId.MenuItem_Watermark : return "水印";

                
case  PreviewStringId.Msg_IncorrectPageRange : return "设置的页边距不正确";
 
                
case  PreviewStringId.TB_TTip_PageSetup : return "页面设置";
                
case  PreviewStringId.TB_TTip_Print : return "打印";
                
case  PreviewStringId.TB_TTip_Export : return "导出";
                
case  PreviewStringId.TB_TTip_Close : return "退出";
                
case  PreviewStringId.TB_TTip_Send : return "发送";
                
default:
                    ret 
= "";
                    
break;
            }

              
            
return ret;
        }


    }


}


调用 PreviewLocalizer.Active = new ChineaseReportLocalizer();  //实现打印本地化
源代码下载:
https://files.cnblogs.com/jhtchina/ReportView.rar
以上是C/S 结构的源码打印
https://files.cnblogs.com/jhtchina/WebPrint源码.rar 
压缩Word文件里面有 使用说明。
是WebForm 下面的源码打印

附加:(控件本地化)
using DevExpress.XtraEditors.Controls;

namespace Oceansoft.LOGERP.Common
{
    
/// <summary>
    
/// =====================================
    
/// 作用: XtraEditors的简体中文本地化类
    
/// =====================================
    
/// 使用方法:
    
/// using Oceansoft.LOGERPDEMO.Common;
    
///    private void Form1_Load(object sender, System.EventArgs e) 
    
///    {
    
///        XtraEditorsSimpChineseLocalizer chnLocalizer = new XtraEditorsSimpChineseLocalizer();
    
///        Localizer.Active = chnLocalizer;
    
///    }
    
/// </summary>

    public class XtraEditorsSimpChineseLocalizer : Localizer
    
{
        
/// <summary>
        
/// 
        
/// </summary>

        public override string Language
        
{
            
get
            
{
                
return "简体中文";
            }

        }


        
/// <summary>
        
/// 
        
/// </summary>
        
/// <param name="id"></param>
        
/// <returns></returns>

        public override string GetLocalizedString(StringId id)
        
{
            
switch (id)
            
{
                
case StringId.CalcButtonBack:
                    
return "Back";
                
case StringId.CalcButtonC:
                    
return "C";
                
case StringId.CalcButtonCE:
                    
return "CE";
                
case StringId.CalcButtonMC:
                    
return "MC";
                
case StringId.CalcButtonMR:
                    
return "MR";
                
case StringId.CalcButtonMS:
                    
return "MS";
                
case StringId.CalcButtonMx:
                    
return "M+";
                
case StringId.CalcButtonSqrt:
                    
return "sqrt";
                
case StringId.CalcError:
                    
return "计算错误";
                
case StringId.Cancel:
                    
return "取消(&C)";
                
case StringId.CaptionError:
                    
return "错误";
                
case StringId.CheckChecked:
                    
return "选中";
                
case StringId.CheckIndeterminate:
                    
return "未选择";
                
case StringId.CheckUnchecked:
                    
return "未选中";
                
case StringId.ColorTabCustom:
                    
return "自定义";
                
case StringId.ColorTabSystem:
                    
return "系统";
                
case StringId.ColorTabWeb:
                    
return "网络";
                
case StringId.DataEmpty:
                    
return "没有图片";
                
case StringId.DateEditClear:
                    
return "清除";
                
case StringId.DateEditToday:
                    
return "今天";
                
case StringId.ImagePopupEmpty:
                    
return "(空的)";
                
case StringId.ImagePopupPicture:
                    
return "(图片)";
                
case StringId.InvalidValueText:
                    
return "无效的值";
                
case StringId.MaskBoxValidateError:
                    
return "The entered value is incomplete. Do you want to correct it?\r\n\r\nYes - return to the editor and correct the value.\r\nNo - leave the value as is.\r\nCancel - reset to the previous value.\r\n ";
                
case StringId.NavigatorAppendButtonHint:
                    
return "附加";
                
case StringId.NavigatorCancelEditButtonHint:
                    
return "取消编辑";
                
case StringId.NavigatorEditButtonHint:
                    
return "编辑";
                
case StringId.NavigatorEndEditButtonHint:
                    
return "结束编辑";
                
case StringId.NavigatorFirstButtonHint:
                    
return "第一条(&F)";
                
case StringId.NavigatorLastButtonHint:
                    
return "最后一条(&L)";
                
case StringId.NavigatorNextButtonHint:
                    
return "下一条(&N)";
                
case StringId.NavigatorNextPageButtonHint:
                    
return "下一页";
                
case StringId.NavigatorPreviousButtonHint:
                    
return "上一条(&P)";
                
case StringId.NavigatorPreviousPageButtonHint:
                    
return "上一页";
                
case StringId.NavigatorRemoveButtonHint:
                    
return "删除(&D)";
                
case StringId.NavigatorTextStringFormat:
                    
return "{0}/{1}条";
                
case StringId.OK:
                    
return "确定(&O)";
                
case StringId.PictureEditMenuCopy:
                    
return "复制(&C)";
                
case StringId.PictureEditMenuCut:
                    
return "剪切(&T)";
                
case StringId.PictureEditMenuDelete:
                    
return "删除(&D)";
                
case StringId.PictureEditMenuLoad:
                    
return "载入(&L)";
                
case StringId.PictureEditMenuPaste:
                    
return "粘贴(&P)";
                
case StringId.PictureEditMenuSave:
                    
return "保存(&S)";
                
case StringId.PictureEditOpenFileError:
                    
return "错误的图片文件格式";
                
case StringId.PictureEditOpenFileErrorCaption:
                    
return "打开失败";
                
case StringId.PictureEditOpenFileFilter:
                    
return "BMP (*.bmp)|*.bmp|JPEG (*.jpg;*.jpeg;*.jpe;*.jfif)|*.jpg;*.jpeg;*.jpe;*.jfif|GIF (*.gif)|*.gif|TIFF (*.tif;*.tiff)|*.tif;*.tiff|PNG (*.png)|*.png|图标 (*.ico)|*.ico|所有图片文件|*.bmp;*.gif;*.jpg;*.jpeg;*.jpe;*.jfif;*.ico;*.png;*.tif;*.tiff|所有文件|*.*";
                
case StringId.PictureEditOpenFileTitle:
                    
return "打开";
                
case StringId.PictureEditSaveFileFilter:
                    
return "BMP (*.bmp)|*.bmp|GIF (*.gif)|*.gif|JPEG (*.jpg)|*.jpg";
                
case StringId.PictureEditSaveFileTitle:
                    
return "另存为";
                
case StringId.TabHeaderButtonClose:
                    
return "关闭(&C)";
                
case StringId.TabHeaderButtonNext:
                    
return "下一页(&N)";
                
case StringId.TabHeaderButtonPrev:
                    
return "上一页(&P)";
                
case StringId.TextEditMenuCopy:
                    
return "复制(&C)";
                
case StringId.TextEditMenuCut:
                    
return "剪切(&T)";
                
case StringId.TextEditMenuDelete:
                    
return "删除(&D)";
                
case StringId.TextEditMenuPaste:
                    
return "粘贴(&P)";
                
case StringId.TextEditMenuSelectAll:
                    
return "全选(&A)";
                
case StringId.TextEditMenuUndo:
                    
return "撤销(&U)";
                
case StringId.UnknownPictureFormat:
                    
return "未知的图片格式";
                
case StringId.XtraMessageBoxAbortButtonText:
                    
return "放弃(&A)";
                
case StringId.XtraMessageBoxCancelButtonText:
                    
return "取消(&C)";
                
case StringId.XtraMessageBoxIgnoreButtonText:
                    
return "忽略(&I)";
                
case StringId.XtraMessageBoxNoButtonText:
                    
return "否(&N)";
                
case StringId.XtraMessageBoxOkButtonText:
                    
return "确定(&O)";
                
case StringId.XtraMessageBoxRetryButtonText:
                    
return "重试(&R)";
                
case StringId.XtraMessageBoxYesButtonText:
                    
return "是(&Y)";
            }

            
return "";
        }

    }

}



using System;
using DevExpress.XtraGrid.Localization;

namespace SZHeritage.Common
{
    
/// <summary>
    
/// =====================================
    
/// 作用: XtraEditors的简体中文本地化类
    
/// 作者: 
    
/// 日期: 2005-08-12
    
/// </summary>

    public class XtraGridSimpChineseLocalizer:GridLocalizer
    
{
        
public XtraGridSimpChineseLocalizer()
        
{
            
//
            
// TODO: 在此处添加构造函数逻辑
            
//
        }

        
public override string Language
        
{
            
get 
            
{
                
return "简体中文";
            }

        }

        
public override string GetLocalizedString(GridStringId id)
        
{
            
switch(id)
            
{
                
case GridStringId.MenuColumnBestFit:
                    
return "适合列宽度";
                
case GridStringId.MenuColumnBestFitAllColumns:
                    
return "适合所有列宽度";
                
case GridStringId.MenuColumnClearFilter:
                    
return "取消筛选";
                
case GridStringId.MenuColumnColumnCustomization:
                    
return "选择显示列";
                
case GridStringId.MenuColumnSortAscending:
                    
return "升序排列";
                
case GridStringId.MenuColumnSortDescending:
                    
return "降序排列";
                
case GridStringId.MenuColumnGroup:
                    
return "此列分组";
                
case GridStringId.MenuColumnGroupBox:
                    
return "自定义分组";
                
case GridStringId.MenuGroupPanelFullCollapse:
                    
return "折叠";
                
case GridStringId.MenuGroupPanelFullExpand:
                    
return "展开";
                
case GridStringId.MenuGroupPanelClearGrouping:
                    
return "清除分组";
                
case GridStringId.GridGroupPanelText:
                    
return "拖动列到此处实现,实现按此列分组";
                
case GridStringId.CustomizationCaption:
                    
return "自定义";
                
            }

            
return "";
        }

    }

}

posted @ 2005-08-24 19:40  jhtchina  阅读(18940)  评论(12编辑  收藏  举报