如何在C#中更改SSRS报告的高度?

如何在C#中更改SSRS报告的高度?,c#,sql-server,reporting-services,ssrs-2008,ssrs-2012,C#,Sql Server,Reporting Services,Ssrs 2008,Ssrs 2012,您好,我正在从事一个MVC项目,在这个项目中,我有一个报告页面,用户可以使用 我需要为报表动态设置页面大小,我尝试了很多方法来解决这个问题,但都做不到 我可以使用此代码更改ReportViewer的大小 rptviewer.Height = Unit.Pixel(520); 请帮我回答以下问题 1.是否可以使用C代码更改SSRS报告页面高度? 2.是否可以在运行时更改纸张大小? 我以前的解决方法 上述逻辑对我都不起作用:-(问题是,为了在呈现过程中控制页面大小,我们需要在运行时将适当的参

您好,我正在从事一个MVC项目,在这个项目中,我有一个报告页面,用户可以使用

我需要为报表动态设置页面大小,我尝试了很多方法来解决这个问题,但都做不到

我可以使用此代码更改ReportViewer的大小

rptviewer.Height = Unit.Pixel(520);
请帮我回答以下问题

1.是否可以使用C代码更改SSRS报告页面高度?

2.是否可以在运行时更改纸张大小?

我以前的解决方法


上述逻辑对我都不起作用:-(

问题是,为了在呈现过程中控制页面大小,我们需要在运行时将适当的参数传递给报表。这将适用于面向页面的物理呈现,如PDF、图像等。这是一个简单的Xml字符串,可以作为参数传递给报表,以控制这些设置。每个导出类型都有一个dif可以通过这种方式重写和控制的不同属性集

在以下示例中,将执行导出为PDF,并传递页面高度和宽度以匹配目标设备的A4纸张大小(第66行):

private void RenderReportToClient()
{
//设置凭据
RSExecuteProxy.ReportExecutionService rs=新的RSExecuteProxy.ReportExecutionService();
rs.Credentials=System.Net.CredentialCache.DefaultCredentials;
RSProxy.ReportingService2005 rsInfo=新的RSProxy.ReportingService2005();
rsInfo.Credentials=System.Net.CredentialCache.DefaultCredentials;
//初始化呈现参数
字节[]结果=空;
字符串reportPath=rptViewer.ServerReport.reportPath;
string format=“PDF”;
字符串historyId=null;
字符串编码;
字符串模拟类型;
字符串扩展;
RSExecuteProxy.Warning[]warnings=null;
字符串[]streamIDs=null;
//初始化执行信息
RSExecuteProxy.ExecutionInfo ExecutionInfo=新的RSExecuteProxy.ExecutionInfo();
RSExecuteProxy.ExecutionHeader ExecutionHeader=新的RSExecuteProxy.ExecutionHeader();
rs.ExecutionHeaderValue=ExecutionHeader;
//得到报告
execInfo=rs.LoadReport(reportPath,historyId);
字符串SessionId=rs.ExecutionHeaderValue.ExecutionID;
//获取参数信息
ReportParameterInfo收集参数=rptViewer.ServerReport.GetParameters();
//计算出我们将有多少个参数
//具有多个值的数组需要有自己的ParameterValue
int paramCount=0;
foreach(参数中的ReportParameterInfo pramInfo)
{
paramCount+=pramInfo.Values.Count;
}
RSExecuteProxy.ParameterValue[]prams=new SSRSWeb.RSExecuteProxy.ParameterValue[paramCount];
int currentPramPosition=0;
//设置婴儿车值
foreach(参数中的ReportParameterInfo pramInfo)
{
foreach(pramInfo.Values中的字符串pramValue)
{
prams[currentPramPosition]=新的SSRSWeb.RSExecuteProxy.ParameterValue();
prams[currentPramPosition].Label=pramInfo.Name;
prams[currentPramPosition].Name=pramInfo.Name;
prams[currentPramPosition]。值=pramValue;
currentPramPosition++;
}
}
rs.SetExecutionParameters(婴儿车,“美国”);
//建立设备设置(A4 8.3×11.7)
string deviceInfo=string.Format(“{0}{1}”、“11.7in”、“8.3in”);
//获取报告字节
结果=rs.Render(格式、deviceInfo、输出扩展名、输出编码、输出mimeType、输出警告、输出StreamID);
Response.ClearContent();
AppendHeader(“内容处置”,“内联;文件名=report.pdf”);
AppendHeader(“content-length”,result.length.ToString());
Response.ContentType=“application/pdf”;
响应。二进制写入(结果);
Response.Flush();
Response.Close();
}

保存报表时,您可以查看PDF并检查属性,注意页面的高度和宽度为8.3英寸x 11.7英寸(如指定)。

您的MVC前端应用程序无法影响报表在报表服务器上的呈现方式。报表查看器对象是保存呈现报表的容器。更改其大小不会影响报表在报表服务器上的呈现方式ect报告中的属性。您能告诉我们有关您试图解决的问题的更多信息吗?当然,我没有告诉您的第一件事是,我没有使用report server,而是使用LocalReport来呈现到我的MVC应用程序。我假设您的意思是,SSRS安装在承载网页的系统上。无论使用哪个系统作为服务器,如果SSRS提供报告,则无法更改报告在外部呈现给SSRS服务的方式。问题的目的是,我们有一个超过40列的大型报告,报告的高度固定为11英寸(在设计报告时在报告属性中指定)。当我们将报告加载到reportviewer时(高度500px)我们可以看到水平和垂直滚动条,这是一个常见的现象。我们计划使此报告更具响应性,因为此报告高度将使用可用的空白空间计算&我们可以将计算出的高度分配给报告,这样我们就可以避免垂直滚动条,并且在所有屏幕大小中它看起来都很好E唯一可能的方法是通过高度(英寸)作为报表的一个参数。在报表中,您可以在运行时修改一些嵌入代码以更改页面大小。但是,我不知道这是否有效,因为这些属性未启用表达式。但是,您肯定必须将参数传递到报表中才能远程执行。您的MVC报表查看器控件是只是一个容器,不会影响报告的定义。
 System.Drawing.Printing.PageSettings pg = new System.Drawing.Printing.PageSettings();
                pg.Margins.Top = 0;
                pg.Margins.Bottom = 0;
                pg.Margins.Left = 0;
                pg.Margins.Right = 0;
                System.Drawing.Printing.PaperSize size = new PaperSize(); 
                size.RawKind = (int)PaperKind.A5;
                pg.PaperSize = size;  
                rptviewer.SetPageSettings(pg);  
                ViewBag.ReportViewer = rptviewer;
                return View("_ReportView");
 System.Drawing.Printing.PageSettings MyPageSize= new System.Drawing.Printing.PageSettings(); 
 MyPageSize.PaperSize = new System.Drawing.Printing.PaperSize("Custom", 17, 12); 
 rptviewer.SetPageSettings(MyPageSize);
var setup = rptviewer.GetPageSettings();           
setup.PaperSize.Height = 1500;
rptviewer.SetPageSettings(setup);
 private void RenderReportToClient()
 {
     //set credentials
     RSExecuteProxy.ReportExecutionService rs = new RSExecuteProxy.ReportExecutionService();
    rs.Credentials = System.Net.CredentialCache.DefaultCredentials;

    RSProxy.ReportingService2005 rsInfo = new RSProxy.ReportingService2005();
    rsInfo.Credentials = System.Net.CredentialCache.DefaultCredentials;
     // init render args
    byte[] result = null;
    string reportPath = rptViewer.ServerReport.ReportPath;
   string format = "PDF";
    string historyId = null;
     string encoding;
    string mimeType;
     string extension;
    RSExecuteProxy.Warning[] warnings = null;
     string[] streamIDs = null;
     //init exec info
     RSExecuteProxy.ExecutionInfo execInfo = new RSExecuteProxy.ExecutionInfo();
     RSExecuteProxy.ExecutionHeader execHeader = new RSExecuteProxy.ExecutionHeader();
     rs.ExecutionHeaderValue = execHeader;
     //get report
     execInfo = rs.LoadReport(reportPath, historyId);
     String SessionId = rs.ExecutionHeaderValue.ExecutionID;
    //get parameter info
     ReportParameterInfoCollection parameters = rptViewer.ServerReport.GetParameters();
    //figure out how many parameters we will have 
     //those with multi-value will need there own ParameterValue in the array
    int paramCount = 0;
     foreach (ReportParameterInfo pramInfo in parameters)
     {
         paramCount += pramInfo.Values.Count;
    }

    RSExecuteProxy.ParameterValue[] prams = new SSRSWeb.RSExecuteProxy.ParameterValue[paramCount];
    int currentPramPosition = 0;

     //set pram values
     foreach (ReportParameterInfo pramInfo in parameters)
     {
         foreach (string pramValue in pramInfo.Values)
         {
           prams[currentPramPosition] = new SSRSWeb.RSExecuteProxy.ParameterValue();
            prams[currentPramPosition].Label = pramInfo.Name;
            prams[currentPramPosition].Name = pramInfo.Name;
         prams[currentPramPosition].Value = pramValue;
            currentPramPosition++;
        }
      }

       rs.SetExecutionParameters(prams, "en-US");

      //build the device settings  (A4 8.3 × 11.7)
       string deviceInfo = string.Format("<DeviceInfo><PageHeight>{0}</PageHeight><PageWidth>{1}</PageWidth></DeviceInfo>", "11.7in", "8.3in");

    //get report bytes
     result = rs.Render(format, deviceInfo, out extension, out encoding, out mimeType, out warnings, out streamIDs);

       Response.ClearContent();
      Response.AppendHeader("Content-Disposition", "inline;filename=report.pdf");
       Response.AppendHeader("content-length", result.Length.ToString());
     Response.ContentType = "application/pdf";
    Response.BinaryWrite(result);
    Response.Flush();
     Response.Close();
   }