xtrareport的使用心得

  近段时间一直在用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("ReportFile")) & "CerDetail.repx")
        rpt.DataSource = ds
        ReportViewer1.Report = rpt

        在这顺便提一下,有的同志提问说ds.Tables.Add(dt)会出现ds中已存在此table,其实通过如下方法就可以解决

        Dim dt As New DataTable
        dt = sm.GetList_CerEmp("").Copy
        dt.TableName = "CerEmp"    ‘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 Sub OnFillEmptySpace(ByVal sender As Object, ByVal e As DevExpress.XtraReports.UI.BandEventArgs)
    Dim Tab As New XRTable()
    Tab.Size = New Size(692, e.Band.Height)
    Tab.location=New Point(8, 0)
    ' Set the table's borders.
    Tab.BorderWidth = 1
    Tab.Borders = DevExpress.XtraPrinting.BorderSide.All


    for i as integer=1 to Convert.ToInt32(e.Band.Height / Me.tableCell18.Height)
      dim row as new XRTableRow
      Row.Size = New Size(692, 25)

      ' Add a collection of cells to the row.
      Row.Cells.AddRange(CreateArrayOfCells(i))
     ' e.Band.Controls.Add(row)
      tab.Rows.Add(Row)

    next i
    e.Band.Controls.Add(tab)
End Sub

Private Function CreateArrayOfCells(byval n as integer)
   ' Create an array of XRTableCell objects.
   Dim CellCollection As XRTableCell() = New XRTableCell(4) {}

   ' Initialize the cells.
   Dim i As Integer
   For i = 0 To CellCollection.Length - 1
      CellCollection(i) = New XRTableCell()
      'CellCollection(i).BackColor = Color.Aqua
      CellCollection(i).TextAlignment = TextAlignment.MiddleCenter
      if n =1 then
        CellCollection(0).font=New Font("楷体_GB2312", 9)
        CellCollection(0).text="以下空白"
      end if
      if i=0 then
         CellCollection(0).Size = New Size(67, 25)
      elseif i=1 then
         CellCollection(1).Size = New Size(118, 25)
      elseif i=2 then
         CellCollection(2).Size = New Size(57, 25)
      elseif i=3 then
         CellCollection(3).Size = New Size(214, 25)
      elseif i=4 then
         CellCollection(4).Size = New Size(236, 25)
      end if
   Next

   Return CellCollection
End Function

     5、打印和导出PDF不能很好的支持中文

      如果字体设置成宋体,打印出来会是小方块,建议使用“微软雅黑“、“楷体_GB2312”、“隶书”等

    6、序号

     Private Sub OnBeforePrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs)
          Dim cell As XRTableCell = DirectCast(sender, XRTableCell)
          Dim report As XtraReport = cell.RootReport
          sender.text=report.CurrentRowIndex + 1
 
    End Sub

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值