近段时间一直在用xtrareport设计报表,所以有一些使用体会和园友们分享。
以前我一直用reportmachine设计报表,不过这次做B/S开发放弃了rm ,不是rm不好用,应该说rm有许多优点,例如两种报表样式,设计报表的速度快,许多功能符合中国式报表等等。但是rm要用在web开发中还是有一些问题的 ,例如报表预览的时候经常失败,还要更改计算机安全等级(也有园友通过支付宝证书进行代码签名解决此问题,不过计算机没有使用过支付宝,这个方案就失败了 ),最要命的是缺少帮助文件,技术支持不太理想。这里就不在具体的评价两种报表工具的优缺点了 ,还是言归正传谈谈心得体会: 1、设计报表
建议通过RibbonEndUserDesignerDemo设计报表。个人感觉要比在VS中设计方便的多。
2、调用报表
Dim rpt As New DevExpress.XtraReports.UI.XtraReport
rpt.LoadLayout(MapPath(Common.ConfigHelper.GetConfigString(\\ rpt.DataSource = ds ReportViewer1.Report = rpt
在这顺便提一下,有的同志提问说ds.Tables.Add(dt)会出现ds中已存在此table,其实通过如下方法就可以解决
Dim dt As New DataTable
dt = sm.GetList_CerEmp(\
dt.TableName = \‘CerEmp自己定义的 ds.Tables.Add(dt) 3、传递参数
Dim rp As New DevExpress.XtraReports.UI.XtraReport
Dim item As New DevExpress.XtraReports.Parameters.Parameter item.Name = \ item.Value = \
rp.Parameters.Add(item)
request parameters 属性设置为NO 4 、追加空白行
通过报表的FillEmptySpace事件就可以实现了 ,给出代码
private void XtraReport_FillEmptySpace(object sender, BandEventArgs e) {
XRTable xrTable = new XRTable();
xrTable.Size = new Size(1066, e.Band.Height); xrTable.Location = new Point(1, 0); xrTable.BorderWidth = 1;
//xrTable.Bounds. = DevExpress.XtraPrinting.BorderSide.All; int SpaceRowCount = e.Band.Height / 25;
XRTableRow[] xrRow = new XRTableRow[SpaceRowCount]; if (SpaceRowCount > 0) {
for (int i = 0; i < SpaceRowCount; i++) {
xrRow[i] = new XRTableRow(); xrRow[i].Size = new Size(1066, 25); xrRow[i].Location = new Point(0, i * 25);
xrRow[i].Borders = ((DevExpress.XtraPrinting.BorderSide)(((DevExpress.XtraPrinting.BorderSide.Left | DevExpress.XtraPrinting.BorderSide.Right)
| DevExpress.XtraPrinting.BorderSide.Bottom))); xrRow[i].BorderWidth = 1; CreateCellArray(xrRow[i]); xrRow[i].BackColor = Color.Red;
//XRTableRow xrRow = new XRTableRow(); }
xrTable.Rows.AddRange(xrRow);
e.Band.Controls.Add(xrTable); } }
///
///在XRTableRow中添加单元格 ///
///
private void CreateCellArray(XRTableRow xrRow) {
int[] ArrCellWidth = new int[] { 27,111,404,102,91,83,83,83,82}; int Xmargin=0;
for (int i = 0; i < ArrCellWidth.Length; i++) {
XRTableCell xrcell = new XRTableCell(); xrcell.BorderWidth = 1; xrcell.Borders =
(DevExpress.XtraPrinting.BorderSide)((DevExpress.XtraPrinting.BorderSide)((DevExpress.XtraPrinting.BorderSide.Right
| DevExpress.XtraPrinting.BorderSide.Bottom))); xrcell.Width = ArrCellWidth[i]; xrcell.Height = 25;
if (i != 0) {
xrcell.Location = new Point(Xmargin + ArrCellWidth[i - 1], 0); } else {
xrcell.Location = new Point(0, 0);