可以实现:
如果您使用的是Table控件,为Table 可在table footer 中实现合计功能:注意下面几行代码:
1. 初始化值时, 添加合计运算表达式:String[] textBoxValues = new String[] { "helloTitle", "Year Released", "MPAA", "=Fields!Title.Value", "=Fields!YearReleased.Value", "=Fields!MPAA.Value", "=Sum(Fields!Title.Value+Fields!YearReleased.Value)", "=Sum(Fields!Title.Value+Fields!YearReleased.Value)", "=Sum(Fields!Title.Value+Fields!YearReleased.Value)" };
2. 将对应Row 设为Table.Footer: table.Footer.TableRows.Add(tableRows[2]);
- Table table = new Table();
- table.Name = "Table1";
- //Creating the rows,columns as well as TableCells for the table as well as TextBoxes to be placed within the Table Cells
- TextBox[] tableTextBoxes = new TextBox[9];
- TableCell[] tableCells = new TableCell[9];
- TableRow[] tableRows = new TableRow[3];
- TableColumn[] tableColumns = new TableColumn[3];
- String[] textBoxValues = new String[] { "helloTitle", "Year Released", "MPAA", "=Fields!Title.Value", "=Fields!YearReleased.Value", "=Fields!MPAA.Value", "=Sum(Fields!Title.Value+Fields!YearReleased.Value)", "=Sum(Fields!Title.Value+Fields!YearReleased.Value)", "=Sum(Fields!Title.Value+Fields!YearReleased.Value)" };
- String[] columnsWidth = new String[] { "9cm", "4.6cm", "5.3cm" };
- String[] rowsHeight = new String[] { "1.5cm", "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[i].Name = "textBox" + (i + 1);
- tableTextBoxes[i].Value = ExpressionInfo.FromString(textBoxValues[i]);
- tableTextBoxes[i].Style.PaddingBottom = tableTextBoxes[i].Style.PaddingLeft = tableTextBoxes[i].Style.PaddingRight = tableTextBoxes[i].Style.PaddingTop = ExpressionInfo.FromString("2pt");
- tableTextBoxes[i].Style.TextAlign = ExpressionInfo.FromString("Left");
- tableCells.SetValue(new TableCell(), i);
- tableCells[i].ReportItems.Add(tableTextBoxes[i]);//Adding the TextBoxes to the TableCells
- if (i < rowsHeight.Length)
- {
- tableRows.SetValue(new TableRow(), i);
- tableRows[i].Height = "1.25cm";
- table.Height += "1.25cm";
- }
- if (i < columnsWidth.Length)
- {
- tableColumns.SetValue(new TableColumn(), i);
- tableColumns[i].Width = columnsWidth[i];
- table.Width += columnsWidth[i];
- table.TableColumns.Add(tableColumns[i]);
- tableCells[i].ReportItems[0].Style.BackgroundColor = ExpressionInfo.FromString("LightBlue");
- tableRows[0].TableCells.Add(tableCells[i]);
- }
- if(i>2 && i<6)
- {
- tableCells[i].ReportItems[0].Style.BackgroundColor = ExpressionInfo.FromString("=Choose((RowNumber("Table1") +1) mod 2, "PaleGreen",)");
- tableRows[1].TableCells.Add(tableCells[i]);
- }
- if (i > 5 && i < 9)
- {
- tableRows[2].TableCells.Add(tableCells[i]);
- }
- }
- table.Header.TableRows.Add(tableRows[0]);
- table.Details.TableRows.Add(tableRows[1]);
- table.Footer.TableRows.Add(tableRows[2]);
- table.Top = "1cm";
- table.Left = "0.635cm";
- report.Report.Body.ReportItems.Add(logo);
- report.Report.Body.ReportItems.Add(table);
复制代码 |