0

我正在做一个项目。其中“rdlc 报告”用于报告。我有一些具有不同大小列的报告。所以我想要的是我想在我的报告属性中给出宽度,我的 rdlc 报告将获得宽度根据该宽度。以前在报告视图模型中给出了宽度大小,如下所示 -

string deviceInfo =

                "<DeviceInfo>" +
                "  <OutputFormat>" + this.Format.ToString() + "</OutputFormat>" +
            "  <PageWidth>8.5in</PageWidth>" +
            "  <PageHeight>8in</PageHeight>" +
            "  <MarginTop>0.5in</MarginTop>" +
            "  <MarginLeft>0.25in</MarginLeft>" +
            "  <MarginRight>0.25in</MarginRight>" +
            "  <MarginBottom>0.5in</MarginBottom>" +
            "</DeviceInfo>";

您可以在下面看到我的完整报告视图模型---

public class ReportViewModel
    {
         public enum ReportFormat         { PDF=1,Word=2,Excel=3}
        public ReportViewModel()
          {
              //initation for the data set holder
               ReportDataSets = new List<ReportDataSet>();
               ReportParams = new List<ReportParameter>();
         }
         //Name of the report
          public string Name { get; set; }

         //Language of the report
          public string ReportLanguage { get; set; }

          //Reference to the RDLC file that contain the report definition
        public string FileName { get; set; }                   
            public string LeftMainTitle { get; set; }
            public string LeftSubTitle { get; set; }
            public string ReportTitle { get; set; }

            //the url for the logo, 
            public string ReportLogo { get; set; }

            //dataset holder
            public List<ReportDataSet> ReportDataSets { get; set; }
            public List<ReportParameter> ReportParams { get; set; }

            //report format needed
            public ReportFormat Format { get; set; }
            public bool ViewAsAttachment { get; set; }

             //an helper class to store the data for each report data set
            public class ReportDataSet
            {
                public string DatasetName { get; set; }
                public List<object> DataSetData { get; set; }
            }
            public class DataSet
            {
                public string DatasetName { get; set; }
                public List<object> DataSetData { get; set; }
            }
            public string ReporExportFileName { get {
                return string.Format("attachment; filename={0}.{1}", this.ReportTitle, ReporExportExtention);
            } }
            public string ReporExportExtention
            {
                get
                {
                    switch (this.Format)
                    {
                        case ReportViewModel.ReportFormat.Word: return  ".doc"; 
                        case ReportViewModel.ReportFormat.Excel: return ".xls"; 
                        default:
                            return ".pdf";
                    }
                }
            }

            public string LastmimeType
            {
                get
                {
                    return mimeType;
                }
            }
            private string mimeType;
            public byte[] RenderReport()
            {
                try
                {
                    //creating a new report and setting its path
                    LocalReport localReport = new LocalReport();
                    localReport.ReportPath = this.FileName;

                    //adding the reort datasets with there names
                    foreach (var dataset in this.ReportDataSets)
                    {
                        ReportDataSource reportDataSource = new ReportDataSource(dataset.DatasetName, dataset.DataSetData);
                        localReport.DataSources.Add(reportDataSource);
                    }
                    //enabeling external images
                    localReport.EnableExternalImages = true;

                    foreach (var item in this.ReportParams)
                    {
                        localReport.SetParameters(item);
                    }

                    //seting the partameters for the report
                    //localReport.SetParameters(new ReportParameter("companyName", this.CompanyTitle));
                    //localReport.SetParameters(new ReportParameter("targetDate", this.TargetDate));
                    //localReport.SetParameters(new ReportParameter("LeftMainTitle", this.LeftMainTitle));
                    //localReport.SetParameters(new ReportParameter("LeftSubTitle", this.LeftSubTitle));
                    //localReport.SetParameters(new ReportParameter("ReportTitle", this.ReportTitle));
                    //localReport.SetParameters(new ReportParameter("ReportLogo", System.Web.HttpContext.Current.Server.MapPath(this.ReportLogo)));
                    //localReport.SetParameters(new ReportParameter("reportDate", this.ReportDate.ToShortDateString()));
                    //localReport.SetParameters(new ReportParameter("UserNamPrinting", this.UserNamPrinting));

                    //preparing to render the report

                    string reportType = this.Format.ToString();

                    string encoding;
                    string fileNameExtension;

                    //The DeviceInfo settings should be changed based on the reportType
                    //http://msdn2.microsoft.com/en-us/library/ms155397.aspx
                    string deviceInfo =
                    "<DeviceInfo>" +
                    "  <OutputFormat>" + this.Format.ToString() + "</OutputFormat>" +
                "  <PageWidth>8.5in</PageWidth>" +
                "  <PageHeight>8in</PageHeight>" +
                "  <MarginTop>0.5in</MarginTop>" +
                "  <MarginLeft>0.25in</MarginLeft>" +
                "  <MarginRight>0.25in</MarginRight>" +
                "  <MarginBottom>0.5in</MarginBottom>" +
                "</DeviceInfo>";

                    Warning[] warnings;
                    string[] streams;
                    byte[] renderedBytes;

                    //Render the report
                    renderedBytes = localReport.Render(
                         reportType,
                         deviceInfo,
                         out mimeType,
                         out encoding,
                        out fileNameExtension,
                         out streams,
                         out warnings);

                    return renderedBytes;

                }
                catch (Exception exc)
                {
                    throw exc;
                }
           }
    }

我想在报告属性中给出宽度大小,如下所示 - 在此处输入图像描述

如何为单个报告提供单个宽度或动态管理宽度?在报告属性中我想设置宽度,我想通过 reportViewModel 中的代码获取该宽度。

"<PageWidth>some code to get width from report properties width</PageWidth>"
4

1 回答 1

1

MSDN我发现了这个——在此处输入图像描述

它让我清楚地知道 RDLC 从报告属性中获取所有类型的样式。它对我不起作用,因为 DeviceInfo 中的“PageWidth”硬编码覆盖了报告属性宽度。所以解决方案是删除它

"  <PageWidth>8.5in</PageWidth>"

来自 deviceInfo 的代码。

于 2017-01-09T11:02:51.573 回答