我正在开展一个项目。在那里" 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>"
答案 0 :(得分:0)
从MSDN我发现了这个 -
它清楚地表明RDLC从Report Properties中获取所有类型的样式。它对我不起作用,因为DeviceInfo中的“PageWidth”硬编码覆盖了Report Properties Width。所以解决方案就是删除它
" <PageWidth>8.5in</PageWidth>"
来自deviceInfo的代码。