如果页面宽度小于要打印的字段的总宽度,如何将字段从 ActiveReports 6.0 报表中的某个部分移动到新页面?

发布于 2025-01-01 00:33:10 字数 543 浏览 3 评论 0原文

我有一个 ActiveReports 6.0 报表,我正在向其中添加要在运行时显示的字段。这些字段和要显示的数据来自 DataGridView。

问题是,当要显示的字段的总宽度高于要打印的页面(例如 A4)的宽度时,这些字段会继续出现在下一个物理页面上,并且碰巧它们会部分打印在一页上。页面并停留在新页面上。

我无法找到任何解决方案,以便如果宽度无法完全打印在当前页面上,我可以将字段移动到新页面。

示例:

有一个 DataGridView,有 8 列,每列宽度为 250 像素,总共 2000 像素,对于 96 DPI 系统来说约为 21 英寸。 A4 纸的宽度约为 8.25 英寸。

边距为
左:0.25 英寸
右:0.25 英寸
顶部:0.69 英寸
底部:0.69 英寸

最初 3 列打印在第 1 页上。第 4 列部分打印在第 1 页上,部分打印在第 2 页上。
我希望第 4 栏无法完全打印在第 1 页上,然后将其移至第 2 页,它将完全打印在第 2 页上

提前致谢

I've a ActiveReports 6.0 report to which I'm adding fields to be displayed at run-time. These fields and the data to be displayed is coming from a DataGridView.

The problem is that when total width of the fields to be displayed goes higher than the width of the page on which it is to be printed e.g. A4, then the fields continue on the next physical page and it happens that they are printed partially on one page and rest on the new page.

I'm unable to find any solution so that i can move the fields to new page if the width can not be printed on the current page completely.

Example:

There is a DataGridView with 8 columns, each having a width of 250 pixels, totalling to 2000 pixels which is approx 21 inches for 96 DPI system. An A4 paper width is approx 8.25 inches.

Margins are
Left : 0.25 Inches
Right : 0.25 Inches
Top : 0.69 Inches
Bottom : 0.69 Inches

Initial 3 columns print on page 1. Column 4 prints partially on Page 1 and partially on Page 2.

I want that as column 4 can not be printed completely on page 1 then move it to Page 2 and it will be printed completely on page 2

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

初与友歌 2025-01-08 00:33:10

水平分页确实很棘手。我想出了下面的函数来处理您的情况:

/// <summary>
/// Horizontally page breaks a control.
/// </summary>
/// <param name="requestedLeft">The requested left position of the control.</param>
/// <param name="controlWidth">The width of the control.</param>
/// <param name="paperWidth">The width of the target paper</param>
/// <param name="leftMargin">The width of the paper's left margin.</param>
/// <param name="rightMargin">The width of the paper's right margin.</param>
/// <returns>The new left position for the control. Will be requestedLeft or greater than requestedLeft.</returns>
public static float HorizontallyPageBreak(float requestedLeft, float controlWidth, float paperWidth, float leftMargin, float rightMargin)
{
    var printArea = paperWidth - (leftMargin + rightMargin);
    var requestedPageNum = (int) (requestedLeft/paperWidth);
    // remove the margins so we can determine the correct target page
    var left = (requestedLeft - ((leftMargin + rightMargin) * requestedPageNum));
    var pageNum = (int)( left / printArea);
    var leftOnPage = left % printArea;
    if (leftOnPage + controlWidth > printArea)
    {   // move it to the next page
        left += printArea - leftOnPage;
        left += rightMargin + leftMargin;
    }
    // add in all the prior page's margins
    left += (leftMargin + rightMargin) * pageNum;
    return left;
}

下面是一个将上述函数与 ActiveReports 一起使用的简单示例:

NewActiveReport1 rpt = new NewActiveReport1();
float controlWidth = 0.53f;
float nextControlLeft = 0f;

for (int controlCount = 0; controlCount < 1000; controlCount++)
{
    var oldLeft = nextControlLeft;
    controlWidth += 0.21f;

    nextControlLeft = HorizontallyPageBreak(nextControlLeft, controlWidth, rpt.PageSettings.PaperWidth, rpt.PageSettings.Margins.Left, rpt.PageSettings.Margins.Right);
    var txt = new DataDynamics.ActiveReports.TextBox();
    txt.Text = "Column " + controlCount;
    txt.Top = 0;
    txt.Border.Color = Color.Black;
    txt.Border.Style = BorderLineStyle.Solid;
    txt.Left = nextControlLeft;
    txt.Width = controlWidth;
    rpt.Sections["detail"].Controls.Add(txt);
    nextControlLeft += controlWidth;
    rpt.PrintWidth = Math.Max(rpt.PrintWidth, nextControlLeft + controlWidth);
}
this.viewer1.Document = rpt.Document;
rpt.Run(true);

Horizontal page breaking is tricky indeed. I came up with the below function to deal with it in your case:

/// <summary>
/// Horizontally page breaks a control.
/// </summary>
/// <param name="requestedLeft">The requested left position of the control.</param>
/// <param name="controlWidth">The width of the control.</param>
/// <param name="paperWidth">The width of the target paper</param>
/// <param name="leftMargin">The width of the paper's left margin.</param>
/// <param name="rightMargin">The width of the paper's right margin.</param>
/// <returns>The new left position for the control. Will be requestedLeft or greater than requestedLeft.</returns>
public static float HorizontallyPageBreak(float requestedLeft, float controlWidth, float paperWidth, float leftMargin, float rightMargin)
{
    var printArea = paperWidth - (leftMargin + rightMargin);
    var requestedPageNum = (int) (requestedLeft/paperWidth);
    // remove the margins so we can determine the correct target page
    var left = (requestedLeft - ((leftMargin + rightMargin) * requestedPageNum));
    var pageNum = (int)( left / printArea);
    var leftOnPage = left % printArea;
    if (leftOnPage + controlWidth > printArea)
    {   // move it to the next page
        left += printArea - leftOnPage;
        left += rightMargin + leftMargin;
    }
    // add in all the prior page's margins
    left += (leftMargin + rightMargin) * pageNum;
    return left;
}

Below is a simple example of using the above function with ActiveReports:

NewActiveReport1 rpt = new NewActiveReport1();
float controlWidth = 0.53f;
float nextControlLeft = 0f;

for (int controlCount = 0; controlCount < 1000; controlCount++)
{
    var oldLeft = nextControlLeft;
    controlWidth += 0.21f;

    nextControlLeft = HorizontallyPageBreak(nextControlLeft, controlWidth, rpt.PageSettings.PaperWidth, rpt.PageSettings.Margins.Left, rpt.PageSettings.Margins.Right);
    var txt = new DataDynamics.ActiveReports.TextBox();
    txt.Text = "Column " + controlCount;
    txt.Top = 0;
    txt.Border.Color = Color.Black;
    txt.Border.Style = BorderLineStyle.Solid;
    txt.Left = nextControlLeft;
    txt.Width = controlWidth;
    rpt.Sections["detail"].Controls.Add(txt);
    nextControlLeft += controlWidth;
    rpt.PrintWidth = Math.Max(rpt.PrintWidth, nextControlLeft + controlWidth);
}
this.viewer1.Document = rpt.Document;
rpt.Run(true);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文