這兩天爲了作報表,研究了一下XtraReport 。爲了添加空行,想了不少辦法。其中若是有分組時,網上給出的辦法就會失敗。
現將經驗公佈一下,但願各位都能少走彎路。
1.加入自定義函數CreateCellArray,用於建立空行。
2.生成報表的 FillEmptySpace 事件,填寫以下代碼。
3.tableDetail 是指細節 區帶
4.****注意,若是有分組,必須將分組PrintAtBottom設置爲true,就是將其下沉。ide
private void CreateCellArray(XRTableRow xrRow, XRTableRow xrRowTemplate) { int Xmargin = 0; for (int i = 0; i < xrRowTemplate.Cells.Count; i++) { XRTableCell xrcell = new XRTableCell(); xrcell.BorderWidth = 1; xrcell.Borders = (DevExpress.XtraPrinting.BorderSide)((BorderSide.Left | BorderSide.Right) | BorderSide.Bottom); xrcell.WidthF = xrRowTemplate.Cells.WidthF; xrcell.BackColor = xrRowTemplate.Cells.BackColor; xrcell.Height = xrRowTemplate.Height; if (i != 0) { xrcell.Location = new Point(Convert.ToInt32(Xmargin + xrRowTemplate.Cells.WidthF), 0); } else { xrcell.Location = new Point(0, 0); } xrRow.Cells.Add(xrcell); } } private void XR_HT_RT_FillEmptySpace(object sender, BandEventArgs e) { XRTable table = tableDetail;//Template Detail Band XRTable int iheight = table.Rows[table.Rows.Count - 1].Height; XRTable xrTable = new XRTable(); xrTable.Size = new Size(table.Width, e.Band.Height - 1); xrTable.BorderWidth = table.BorderWidth; xrTable.Location = table.Location; xrTable.BackColor = table.BackColor; int SpaceRowCount = e.Band.Height / iheight; XRTableRow[] xrRow = new XRTableRow[SpaceRowCount]; if (SpaceRowCount > 0) { for (int i = 0; i < SpaceRowCount; i++) { xrRow = new XRTableRow(); xrRow.Size = new Size(table.Width, iheight); xrRow.Location = new Point(table.Location.X, i * iheight); xrRow.Borders = (DevExpress.XtraPrinting.BorderSide)((BorderSide.Left | BorderSide.Right) | BorderSide.Bottom); xrRow.BorderWidth = 1; xrRow.BorderColor = table.Rows[table.Rows.Count - 1].BorderColor; //CreateCell XRTableRow row = table.Rows[table.Rows.Count - 1]; CreateCellArray(xrRow, row); } xrTable.Rows.AddRange(xrRow); e.Band.Controls.Add(xrTable); } }