程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> 關於.NET >> xtrareport的使用心得

xtrareport的使用心得

編輯:關於.NET

以前我一直用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”、“隸書”等

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

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved