zoukankan      html  css  js  c++  java
  • .repx模板参数填充

            
    引用dll
    DevExpress.Printing.v17.1.Core.dll
    DevExpress.XtraReports.v17.1.dll


    public void Print(PaperKind PagerKind, ReportModel rm, string fileName) { XtraReport r = new XtraReport(); string ls_temp = DirFileHelper.GetAbsolutePath(rm.templateName) ;//模板路径 if (!File.Exists(ls_temp)) { //MessageBox.Show("未找到模板!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } r.LoadLayout(ls_temp); r.DataAdapter = null; r.DataMember = null; r.PrintingSystem.ShowMarginsWarning = false; r.PrintingSystem.ShowPrintStatusDialog = false; r.ExportOptions.Xls.TextExportMode = DevExpress.XtraPrinting.TextExportMode.Text; r.ExportOptions.Xlsx.TextExportMode = DevExpress.XtraPrinting.TextExportMode.Text; r.DataSource = rm.List_Data;//明细数据 r.PrintingSystem.PageSettings.PaperKind = PagerKind; r.PaperKind = PagerKind;//纸张大小 #region 绑定参数
    if (rm.BaseParamter_DT != null && rm.BaseParamter_DT.Rows.Count > 0)//主表数据 { for (int i = 0; i < rm.BaseParamter_DT.Columns.Count; i++) { if (r.Parameters[rm.BaseParamter_DT.Columns[i].ColumnName] == null) { continue; } try { r.Parameters[rm.BaseParamter_DT.Columns[i].ColumnName].Value = rm.BaseParamter_DT.Rows[0][i] == null ? "" : rm.BaseParamter_DT.Rows[0][i]; } catch (Exception ex) { // MessageBox.Show(ex.Message); } } } foreach (KeyValuePair<string, object> item_Ext in rm.BaseParamter_Ext) { if (r.Parameters[item_Ext.Key] == null) continue; r.Parameters[item_Ext.Key].Value = item_Ext.Value; } r.CreateDocument(); #endregion #region 根据控件名绑定数据 if (!rm.BandDataByControlName.IsNullOrEmpty()) { foreach (var item_control in rm.BandDataByControlName) { var ctl = r.FindControl(item_control.Key, true); if (ctl != null) { if (ctl is DevExpress.XtraReports.UI.XRCheckBox) { ((ctl as DevExpress.XtraReports.UI.XRCheckBox).Checked) = item_control.Value.IsTrue(); } else { ctl.Text = item_control.Value.Cast<string>(); } } } } #endregion #region 绑定复选框 if (rm.BandDataForCheckBox != null && rm.BandDataForCheckBox.Length > 0) { var val = rm.BandDataForCheckBox.Split('|'); string[] val_key = null; foreach (var item_control in val) { val_key = item_control.Split(':'); dynamic ctl = r.FindControl(val_key[0], true); if (ctl != null) { if (ctl is DevExpress.XtraReports.UI.XRCheckBox) { var param = new DevExpress.XtraReports.Parameters.Parameter(); param.Type = typeof(bool); param.Value = val_key[1].IsTrue(); param.Name = val_key[0]; param.Visible = false; r.Parameters.Add(param); var bind = new XRBinding(param, "Checked", null); ctl.DataBindings.Add(bind); } } } } #endregion string virtualPath = $"{DateTime.Now.Year.ToString()}/{DateTime.Now.Month.ToString()}/{DateTime.Now.ToString("yyyyMMddHHmmss")}_{fileName}"; string fullFileName = $"{Config.GetValue("AnnexesFile")}/{virtualPath}";//保存路径 r.ExportToImage(fullFileName);//保存为图片 }
  • 相关阅读:
    jQuery中的prop和attr区别
    echarts 不同区域背景色不同 废了我一天的时间
    echarts 饼状图 改变折线长度
    jqGrid有关问题 小知识点
    echarts页面中多图自适应
    bootstrap详解 见网址
    前端自适应布局方法总结
    前端页面中如何在窗口缩放时让两个div始终在同一行显示
    Vue2.0 v-for 中 :key 到底有什么用?
    sublime中安装package control总是失败
  • 原文地址:https://www.cnblogs.com/zhusk/p/10901016.html
Copyright © 2011-2022 走看看