ming 发表于 2016-12-15 11:14:46

请教动态位置报表要如何实现

你好,输出报表基本报表如图1:包含A-G等7个字段,在实际应用中,需要按选择条件组合,将A-G各个字段放入不同行列中,这样将近会有5K种组合,请问能否有动态报表形式来实现这样的输出方式
图1:

标题A标题B标题C标题D标题E
标题F
标题G
字段A字段B字段C字段D值


图2:

标题B标题A标题C标题D标题E
标题F
标题G
字段B字段A字段C字段D值

Lenka.Guo 发表于 2016-12-15 11:33:39

您好,

您的需求是 有7个字段,需要根据用户输入来重置这7个字段的位置。
如果表格的整体结构是固定的,只是修改字段值得位置,那么可以通过后台代码,动态创建表格,并为每一个单元格附上对应的值。您可以参考本地示例中完全动态的创建表格 CreatReport C:\Users\lenkaguo\Documents\GrapeCity Samples\ActiveReports 10\Page Reports And RDL Reports\API\CreateReport


TextBox[] tableTextBoxes = new TextBox;
            TableCell[] tableCells = new TableCell;
            TableRow[] tableRows = new TableRow;
            TableColumn[] tableColumns = new TableColumn;
            String[] textBoxValues = new String[] { "Title", "Year Released", "MPAA", "=Fields!Title.Value", "=Fields!YearReleased.Value", "=Fields!MPAA.Value" };
            String[] columnsWidth = new String[] { "9cm", "4.6cm", "5.3cm" };
            String[] rowsHeight = new String[] { "1.5cm", "1.5cm" };
            //Setting properties for the Textboxes to be placed in the TableCells
            for (int i = 0; i < tableTextBoxes.Length; i++)
            {
                tableTextBoxes.SetValue(new TextBox(), i);
                tableTextBoxes.Name = "textBox" + (i + 1);
                tableTextBoxes.Value = ExpressionInfo.FromString(textBoxValues);
                tableTextBoxes.Style.PaddingBottom = tableTextBoxes.Style.PaddingLeft = tableTextBoxes.Style.PaddingRight = tableTextBoxes.Style.PaddingTop = ExpressionInfo.FromString("2pt");
                tableTextBoxes.Style.TextAlign = ExpressionInfo.FromString("Left");
                tableCells.SetValue(new TableCell(), i);
                tableCells.ReportItems.Add(tableTextBoxes);//Adding the TextBoxes to the TableCells
                if (i < rowsHeight.Length)
                {
                  tableRows.SetValue(new TableRow(), i);
                  tableRows.Height = "1.25cm";
                  table.Height += "1.25cm";
                }
                if (i < columnsWidth.Length)
                {
                  tableColumns.SetValue(new TableColumn(), i);
                  tableColumns.Width = columnsWidth;
                  table.Width += columnsWidth;
                  table.TableColumns.Add(tableColumns);
                  tableCells.ReportItems.Style.BackgroundColor = ExpressionInfo.FromString("LightBlue");
                  tableRows.TableCells.Add(tableCells);
                }
                else
                {
                  tableCells.ReportItems.Style.BackgroundColor = ExpressionInfo.FromString("=Choose((RowNumber(\"Table1\") +1) mod 2, \"PaleGreen\",)");
                  tableRows.TableCells.Add(tableCells);
                }
            }
            table.Header.TableRows.Add(tableRows);

ming 发表于 2016-12-15 11:43:16

矩表可以用这种方式现实吗?

Lenka.Guo 发表于 2016-12-15 15:21:30

ming 发表于 2016-12-15 11:43
矩表可以用这种方式现实吗?

如果报表中没有需要动态生成的列,建议还是选择表格控件,结构相对简单而且有现成的示例。

矩表也可以使用后台代码来创建,只是矩表涉及到动态行列的功能,所以组织结构也相对复杂。示例代码:
TablixRow row = new TablixRow();
                                        TablixCell cel = new TablixCell();
                       
                                        cel.CellContents = new CellContents();
                                        cel.CellContents.ColSpan = 1;
                                        cel.CellContents.RowSpan = 1;

                                        var tb = new TextBox();
                                        tb.Value = "Text1";
                                        tb.Name = "Text1";
                                        tb.CanGrow = true;
                                        tb.Height = height;
                                        tb.Width = width;

                                        cel.CellContents.ReportItem = tb;
                                        row.TablixCells.Add(cel);
                                        row.Height = rowHeight;

                                        tblx.TablixBody.TablixRows.Add(row);

                                        var tm = new TablixMember();
                                        var g = new Grouping();
                                        g.Name = "New Grouping";
                                        tm.Grouping = g;

                                        TablixHeader th = new TablixHeader();
                                        th.Size = size;
                                        th.CellContents = new CellContents();
                                        th.CellContents.RowSpan = 1;
                                        th.CellContents.ColSpan = 1;

                                        tb = new TextBox();
                                        tb.Name = "Text2";
                                        tb.Value = "Text2";
                                        tb.CanGrow = true;
                                        tb.Height = height;
                                        tb.Width = width;

                                        th.CellContents.ReportItem = tb;
                                        tm.TablixHeader = th;
                                        tm.Parent = tblx.TablixRowHierarchy;
                                        tblx.TablixRowHierarchy.TablixMembers.Add(tm);

                                        tblx.Height += height;





ming 发表于 2017-1-10 13:25:48

请问我是否可以先创建一个矩表的模板(如一楼图示),然后将其中各栏的标题及内容以参数代之,最后在后台代码中,根据需求把不同的内容放入参数中,形成不同的显示样式,不知道这样的方式,矩表是否支持?

Lenka.Guo 发表于 2017-1-10 14:10:10

这样的做法是不支持的哦,矩表需要绑定字段,来进行行分组和列分组,而且参数如果是多值的话是无法在数据控件上显示的。

ming 发表于 2017-1-10 15:59:56

或者说,标题不通过参数,是绑定数据源的时候,再动态指定字段,这样可以吗?

Lenka.Guo 发表于 2017-1-10 17:08:14

那就又回到2,3楼说的,通过后台代码来指定。
页: [1]
查看完整版本: 请教动态位置报表要如何实现