微软报告景观问题

时间:2013-05-07 10:18:01

标签: c# .net winforms

我使用c#中的微软报告查看器生成了报告。

为了使报告以横向视图打印,我使用了代码:

reportViewer1.PrinterSettings.DefaultPageSettings.Landscape = true;

此代码我放置在Form Load事件以及reportviewer load事件中,如下所示:

private void BillPDF_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'dsBillPDF.totalBill' table. You can move, or remove it, as needed.
            this.totalBillTableAdapter.Fill(this.dsBillPDF.totalBill,AllBill.fromDate);
            reportViewer1.PrinterSettings.DefaultPageSettings.Landscape = true;
            this.reportViewer1.RefreshReport();
        }

        private void reportViewer1_Load(object sender, EventArgs e)
        {
            reportViewer1.PrinterSettings.DefaultPageSettings.Landscape = true;
        }

不幸的是,此代码无效。

使用reportViewer1.PrinterSettings.DefaultPageSettings.Landscape = true;是错误的吗?或者我把它写错了。

请帮帮我。

3 个答案:

答案 0 :(得分:7)

乍一看,您的代码看起来很好。我发现每次改变方向时我都需要刷新报告。根据经验,我遇到了与使用ReportViewer进行景观美化相同的问题。您需要更改宽度和高度设置,以使宽度大于高度。

选择报告属性

此屏幕截图的白色部分是我报告的底部。现在只需右键点击,然后在报告页脚下方(空白处的任意位置)选择“报告属性... ”。

Right Click

报告属性

在这里,您还可以将方向设置为横向(但您是通过代码完成的,这样就可以了)。确保您的打印机支持纸张尺寸格式(在我们的例子中为Letter)... 某些打印机不会处理“自定义”格式

如果宽度仍然小于高度,请手动调整,您应该可以解决问题。

保证金也很重要。无论何时打印和/或导出为PDF,您都可能想要使用边距。每当我这样做时,ReportViewer都会给我带来一些问题。

Report Properties

如果所有这些都失败了,请尝试像这样展开报告并重复属性过程: Report ruler set to 27cm

我的.rdlc上的报告标尺设置为27厘米左右。

我的代码snipet(VB.NET)

    sReportDataSource.Name = "rptBillDataset" 'Dataset name associated to the report
    sReportDataSource.Value = ds.dsBillDetail 'Dataset value
    rv.rvRdlc.LocalReport.DataSources.Add(sReportDataSource)
    rv.rvRdlc.PrinterSettings.DefaultPageSettings.Landscape = True
    rv.rvRdlc.RefreshReport()
    rv.Show()

答案 1 :(得分:0)

System.Drawing.Printing.PageSettings ps = new System.Drawing.Printing.PageSettings();

ps.Landscape = true;

this.reportViewer1.SetPageSettings(PS);

在VS 2010 Pro中为我工作

答案 2 :(得分:0)

如果您这样做,您将获得当前页面设置而不是默认设置

System.Drawing.Printing.PageSettings ps = reportViewer1.GetPageSettings();
ps.Landscape = true;
reportViewer1.SetPageSettings(ps);