原創(chuàng)|其它|編輯:郝浩|2012-08-31 15:57:45.000|閱讀 2949 次
概述:本文主要講述使用xtrareport設(shè)計(jì)報(bào)表,調(diào)用報(bào)表,傳遞參數(shù),追加空白行,打印導(dǎo)出PDF方面的心得體會(huì)。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
以前我一直用reportmachine設(shè)計(jì)報(bào)表,不過(guò)這次做B/S開(kāi)發(fā)放棄了rm ,不是 rm不好用,應(yīng)該說(shuō)rm有許多優(yōu)點(diǎn),例如兩種報(bào)表樣式,設(shè)計(jì)報(bào)表的速度快,許多 功能符合中國(guó)式報(bào)表等等。但是rm要用在web開(kāi)發(fā)中還是有一些問(wèn)題的 ,例如報(bào) 表預(yù)覽的時(shí)候經(jīng)常失敗,還要更改計(jì)算機(jī)安全等級(jí)(也有園友通過(guò)支付寶證書(shū)進(jìn) 行代碼簽名解決此問(wèn)題,不過(guò)計(jì)算機(jī)沒(méi)有使用過(guò)支付寶,這個(gè)方案就失敗了 ) ,最要命的是缺少幫助文件,技術(shù)支持不太理想。這里就不在具體的評(píng)價(jià)兩種報(bào) 表工具的優(yōu)缺點(diǎn)了 ,還是言歸正傳談?wù)勑牡皿w會(huì):
1、設(shè)計(jì)報(bào)表
建議通過(guò)RibbonEndUserDesignerDemo設(shè)計(jì)報(bào)表。個(gè)人感覺(jué)要比在VS中設(shè)計(jì)方 便的多。
2、調(diào)用報(bào)表
Dim rpt As New DevExpress.XtraReports.UI.XtraReport
rpt.LoadLayout(MapPath (Common.ConfigHelper.GetConfigString("ReportFile")) & "CerDetail.repx")
rpt.DataSource = ds
ReportViewer1.Report = rpt
在這順便提一下,有的同志提問(wèn)說(shuō)ds.Tables.Add(dt)會(huì)出現(xiàn)ds中已存在此 table,其實(shí)通過(guò)如下方法就可以解決
Dim dt As New DataTable
dt = sm.GetList_CerEmp("").Copy
dt.TableName = "CerEmp" ‘CerEmp自己定義的
ds.Tables.Add(dt)
3、傳遞參數(shù)
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 屬性設(shè)置為NO
4 、追加空白行
通過(guò)報(bào)表的FillEmptySpace事件就可以實(shí)現(xiàn)了 ,給出代碼
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、打印和導(dǎo)出PDF不能很好的支持中文
如果字體設(shè)置成宋體,打印出來(lái)會(huì)是小方塊,建議使用“微軟雅黑“、“楷 體_GB2312”、“隸書(shū)”等。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:轉(zhuǎn)自博客園 作者風(fēng)崖