【问题标题】:RDLC reports are not respecting my page height optionRDLC 报告不尊重我的页面高度选项
【发布时间】:2020-02-26 00:48:37
【问题描述】:

我正在将此 DeviceInfo 传递给报告:

<DeviceInfo>
  <OutputFormat>Word</OutputFormat>
  <PageWidth>11in</PageWidth>
  <PageHeight>8.5in</PageHeight>
  <MarginTop>1in</MarginTop>
  <MarginLeft>0.5in</MarginLeft>
  <MarginRight>0.5in</MarginRight>
  <MarginBottom>1in</MarginBottom>
</DeviceInfo>

但是,当报表呈现(Word 或 PDF)时,页面大小为 11 x 11 英寸,而不是 11 x 8.5(横向)。为什么是这样?如何让报表以适当的大小呈现?

这里是我呈现报告的地方:

byte[] bytes = Report.Render( // Report is an instance of the Microsoft.Reporting.WebForms.LocalReport class
    reportType,
    deviceInfo, // this contains the XML above
    out mimeType,
    out encoding,
    out fileNameExtension,
    out streams,
    out warnings);

【问题讨论】:

    标签: reporting rdlc


    【解决方案1】:

    在报表生成器或 Visual Studio 中,您还必须将报表的布局设置为 Landscape,以便它知道如何呈现

    【讨论】:

    • 嗯,我没有使用报表生成器或 Visual Studio 来定义报表;而是我使用 C# 代码来生成报告。你知道这会在哪里设置吗?
    • 您正在使用 C# 代码生成*.rdlc 文件?你可以试试这个:System.Drawing.Printing.PageSettings ps = new System.Drawing.Printing.PageSettings(); ps.Landscape = true; ps.PaperSize = new System.Drawing.Printing.PaperSize("A4", 827, 1170); ps.PaperSize.RawKind = (int)System.Drawing.Printing.PaperKind.A4; reportViewer.SetPageSettings(ps);我没试过,试试看:)
    • 我没有使用ReportViewer;使用上面的Report.Render 调用将报告生成为 HTML、PDF、Word 或 Excel。
    • 我不确定我是否理解正确,您如何创建rdlc 文件的定义文件? - 如果您不使用 ReportViewer,请尝试至少在代码中使用以导出报告而不是将其放置在 GUI 中
    • RDLC 是使用各种自定义类生成的,这些类输出各种 RDLC XML 元素。
    【解决方案2】:

    报告页面大小似乎没有正确初始化,所以我这样做了:

    var page = report.Page;
    
    page.LeftMargin = LeftMargin;
    page.RightMargin = RightMargin;
    
    page.TopMargin = TopMargin;
    page.BottomMargin = BottomMargin;
    
    // I added these next two lines
    page.PageWidth = PageWidth;
    page.PageHeight = PageHeight;
    

    【讨论】:

      猜你喜欢
      • 2017-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多