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)
      'Row.location=New Point(8, i*25)

      ' Make the borders for all its cells visible.
      'Row.Borders = DevExpress.XtraPrinting.BorderSide.All

      ' Sets the border width for all its cells.
      'Row.BorderWidth = 1

      ' 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”、“隶书”等

 

    以上有些可能不能不是最好的方法,请园友指正

    

posted on 2009-04-18 10:32  rex.ying  阅读(1588)  评论(0编辑  收藏  举报