JasperReports/iReport中,Text Field的字串長度過長,如何自動斷行(換行),避免值被截斷
来源:互联网 发布:齐鲁通达信软件下载 编辑:程序博客网 时间:2024/06/07 03:39
版本
JasperReports版本為4.0.1。
前言
有個報表設計如下,其中紅框處的Text Field其寬度為226。
此份報表的資料來源,包含了三筆記錄,其中有一筆記錄的ADDRESS為「大台南市永康區永元路123段456巷789弄876號543樓之21室」。如果報表不做任何設定,則產生出來的報表,這筆記錄的ADDRESS會被截斷成如下圖紅框處(之21室消失了):
解決方案一
這時候解決方式之一是增加band的高度,同時增加每個Text Field的高度,如下圖:
但這樣子的調整只是治標不治本,因為日後可能會有新的記錄,其ADDRESS的字串長度更長;而且上述的調整會導致所有記錄的高度都增加,如下圖:
解決方案二
為了彈性調整每筆記錄的高度,而且能夠正確顯示ADDRESS,使其不會被截斷(亦即自動換行),可以設定Text Field的屬性《Stretch With Overflow》為true,如下圖。如此一來,當ADDRESS長度超過Text Field的長度時,會自動伸展Text Field的高度,以顯示完整的ADDRESS。
但是,上述做法只會伸展有設定《Stretch With Overflow》為true的Text Field而已,亦即不會變動其他Text Field的高度,造成如下圖中格線沒有對齊的情形:
這時候要調整其他欄位的《Stretch Type》屬性,將其設成Relative to Band Height,則報表的格線就會對齊了:
可是這時折行後的字卻會蓋到格線,要解決這種情形,就得調整Text Field的padding,做法如下:
1. 對Text Field點選右鍵,選擇Padding And Borders,如下圖。
2. 在出現的視窗中,將Padding frame中的Bottom的值從0改成5,然後按下OK。
調整後產生的報表為:
結論
要避免Text Field的值,其字串長度過長,而無法完全顯示在Text Field中,亦即自動換行,總共有三個步驟:
1. 設定可能字串長度過長的Text Field的屬性《Stretch With Overflow》為true。
2. 設定其他Text Field的屬性《Stretch Type》為Relative to Band Height。
3. 調整Text Field的padding。
jrxml
JasperReports版本為4.0.1。
前言
有個報表設計如下,其中紅框處的Text Field其寬度為226。
此份報表的資料來源,包含了三筆記錄,其中有一筆記錄的ADDRESS為「大台南市永康區永元路123段456巷789弄876號543樓之21室」。如果報表不做任何設定,則產生出來的報表,這筆記錄的ADDRESS會被截斷成如下圖紅框處(之21室消失了):
解決方案一
這時候解決方式之一是增加band的高度,同時增加每個Text Field的高度,如下圖:
但這樣子的調整只是治標不治本,因為日後可能會有新的記錄,其ADDRESS的字串長度更長;而且上述的調整會導致所有記錄的高度都增加,如下圖:
解決方案二
為了彈性調整每筆記錄的高度,而且能夠正確顯示ADDRESS,使其不會被截斷(亦即自動換行),可以設定Text Field的屬性《Stretch With Overflow》為true,如下圖。如此一來,當ADDRESS長度超過Text Field的長度時,會自動伸展Text Field的高度,以顯示完整的ADDRESS。
但是,上述做法只會伸展有設定《Stretch With Overflow》為true的Text Field而已,亦即不會變動其他Text Field的高度,造成如下圖中格線沒有對齊的情形:
這時候要調整其他欄位的《Stretch Type》屬性,將其設成Relative to Band Height,則報表的格線就會對齊了:
可是這時折行後的字卻會蓋到格線,要解決這種情形,就得調整Text Field的padding,做法如下:
1. 對Text Field點選右鍵,選擇Padding And Borders,如下圖。
2. 在出現的視窗中,將Padding frame中的Bottom的值從0改成5,然後按下OK。
調整後產生的報表為:
結論
要避免Text Field的值,其字串長度過長,而無法完全顯示在Text Field中,亦即自動換行,總共有三個步驟:
1. 設定可能字串長度過長的Text Field的屬性《Stretch With Overflow》為true。
2. 設定其他Text Field的屬性《Stretch Type》為Relative to Band Height。
3. 調整Text Field的padding。
jrxml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
<
jasperreport
xmlns
=
"http://jasperreports.sourceforge.net/jasperreports"
xmlns:xsi
=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation
=
"http://jasperreports.sourceforge.net/jasperreportshttp://jasperreports.sourceforge.net/xsd/jasperreport.xsd"
name
=
"Report"
pageWidth
=
"595"
pageHeight
=
"842"
columnWidth
=
"555"
leftMargin
=
"20"
rightMargin
=
"20"
topMargin
=
"20"
bottomMargin
=
"20"
>
<
property
name
=
"ireport.zoom"
value
=
"1.4641000000000006"
/>
<
property
name
=
"ireport.x"
value
=
"0"
/>
<
property
name
=
"ireport.y"
value
=
"75"
/>
<
querystring
language
=
"SQL"
>
<![CDATA[SELECT
HOWARD_CUSTOMER."ID" AS HOWARD_CUSTOMER_ID,
HOWARD_CUSTOMER."NAME" AS HOWARD_CUSTOMER_NAME,
HOWARD_CUSTOMER."TEL" AS HOWARD_CUSTOMER_TEL,
HOWARD_CUSTOMER."ADDRESS" AS HOWARD_CUSTOMER_ADDRESS
FROM
"HOWARD_CUSTOMER" HOWARD_CUSTOMER]]>
</
queryString
>
<
field
name
=
"HOWARD_CUSTOMER_ID"
class
=
"java.lang.String"
/>
<
field
name
=
"HOWARD_CUSTOMER_NAME"
class
=
"java.lang.String"
/>
<
field
name
=
"HOWARD_CUSTOMER_TEL"
class
=
"java.lang.String"
/>
<
field
name
=
"HOWARD_CUSTOMER_ADDRESS"
class
=
"java.lang.String"
/>
<
title
>
<
band
height
=
"59"
splitType
=
"Stretch"
>
<
statictext
>
<
reportelement
x
=
"230"
y
=
"0"
width
=
"81"
height
=
"59"
/>
<
textelement
>
<
font
size
=
"36"
isBold
=
"true"
/>
</
textElement
>
<
text
>
<![CDATA[Test]]>
</
text
>
</
staticText
>
</
band
>
</
title
>
<
columnheader
>
<
band
height
=
"20"
splitType
=
"Stretch"
>
<
statictext
>
<
reportelement
x
=
"0"
y
=
"0"
width
=
"53"
height
=
"20"
/>
<
box
>
<
pen
lineWidth
=
"1.0"
lineStyle
=
"Solid"
/>
<
toppen
lineWidth
=
"1.0"
lineStyle
=
"Solid"
/>
<
leftpen
lineWidth
=
"1.0"
lineStyle
=
"Solid"
/>
<
bottompen
lineWidth
=
"1.0"
lineStyle
=
"Solid"
/>
<
rightpen
lineWidth
=
"1.0"
lineStyle
=
"Solid"
/>
</
box
>
<
textElement
/>
<
text
>
<![CDATA[ID]]>
</
text
>
</
staticText
>
<
statictext
>
<
reportelement
x
=
"53"
y
=
"0"
width
=
"138"
height
=
"20"
/>
<
box
>
<
pen
lineWidth
=
"1.0"
lineStyle
=
"Solid"
/>
<
toppen
lineWidth
=
"1.0"
lineStyle
=
"Solid"
/>
<
leftpen
lineWidth
=
"1.0"
lineStyle
=
"Solid"
/>
<
bottompen
lineWidth
=
"1.0"
lineStyle
=
"Solid"
/>
<
rightpen
lineWidth
=
"1.0"
lineStyle
=
"Solid"
/>
</
box
>
<
textElement
/>
<
text
>
<![CDATA[NAME]]>
</
text
>
</
staticText
>
<
statictext
>
<
reportelement
x
=
"191"
y
=
"0"
width
=
"138"
height
=
"20"
/>
<
box
>
<
pen
lineWidth
=
"1.0"
lineStyle
=
"Solid"
/>
<
toppen
lineWidth
=
"1.0"
lineStyle
=
"Solid"
/>
<
leftpen
lineWidth
=
"1.0"
lineStyle
=
"Solid"
/>
<
bottompen
lineWidth
=
"1.0"
lineStyle
=
"Solid"
/>
<
rightpen
lineWidth
=
"1.0"
lineStyle
=
"Solid"
/>
</
box
>
<
textElement
/>
<
text
>
<![CDATA[PHONE NO]]>
</
text
>
</
staticText
>
<
statictext
>
<
reportelement
x
=
"329"
y
=
"0"
width
=
"226"
height
=
"20"
/>
<
box
>
<
pen
lineWidth
=
"1.0"
lineStyle
=
"Solid"
/>
<
toppen
lineWidth
=
"1.0"
lineStyle
=
"Solid"
/>
<
leftpen
lineWidth
=
"1.0"
lineStyle
=
"Solid"
/>
<
bottompen
lineWidth
=
"1.0"
lineStyle
=
"Solid"
/>
<
rightpen
lineWidth
=
"1.0"
lineStyle
=
"Solid"
/>
</
box
>
<
textElement
/>
<
text
>
<![CDATA[ADDRESS]]>
</
text
>
</
staticText
>
</
band
>
</
columnHeader
>
<
detail
>
<
band
height
=
"18"
splitType
=
"Immediate"
>
<
textfield
>
<
reportelement
stretchType
=
"RelativeToBandHeight"
x
=
"0"
y
=
"0"
width
=
"53"
height
=
"18"
/>
<
box
>
<
pen
lineWidth
=
"1.0"
lineStyle
=
"Solid"
/>
<
toppen
lineWidth
=
"1.0"
lineStyle
=
"Solid"
/>
<
leftpen
lineWidth
=
"1.0"
lineStyle
=
"Solid"
/>
<
bottompen
lineWidth
=
"1.0"
lineStyle
=
"Solid"
/>
<
rightpen
lineWidth
=
"1.0"
lineStyle
=
"Solid"
/>
</
box
>
<
textElement
/>
<
textfieldexpression
class
=
"java.lang.String"
>
<![CDATA[$F{HOWARD_CUSTOMER_ID}]]>
</
textFieldExpression
>
</
textField
>
<
textfield
>
<
reportelement
stretchType
=
"RelativeToBandHeight"
x
=
"53"
y
=
"0"
width
=
"138"
height
=
"18"
/>
<
box
>
<
pen
lineWidth
=
"1.0"
lineStyle
=
"Solid"
/>
<
toppen
lineWidth
=
"1.0"
lineStyle
=
"Solid"
/>
<
leftpen
lineWidth
=
"1.0"
lineStyle
=
"Solid"
/>
<
bottompen
lineWidth
=
"1.0"
lineStyle
=
"Solid"
/>
<
rightpen
lineWidth
=
"1.0"
lineStyle
=
"Solid"
/>
</
box
>
<
textElement
/>
<
textfieldexpression
class
=
"java.lang.String"
>
<![CDATA[$F{HOWARD_CUSTOMER_NAME}]]>
</
textFieldExpression
>
</
textField
>
<
textfield
>
<
reportelement
stretchType
=
"RelativeToBandHeight"
x
=
"191"
y
=
"0"
width
=
"138"
height
=
"18"
/>
<
box
>
<
pen
lineWidth
=
"1.0"
lineStyle
=
"Solid"
/>
<
toppen
lineWidth
=
"1.0"
lineStyle
=
"Solid"
/>
<
leftpen
lineWidth
=
"1.0"
lineStyle
=
"Solid"
/>
<
bottompen
lineWidth
=
"1.0"
lineStyle
=
"Solid"
/>
<
rightpen
lineWidth
=
"1.0"
lineStyle
=
"Solid"
/>
</
box
>
<
textElement
/>
<
textfieldexpression
class
=
"java.lang.String"
>
<![CDATA[$F{HOWARD_CUSTOMER_TEL}]]>
</
textFieldExpression
>
</
textField
>
<
textfield
isStretchWithOverflow
=
"true"
>
<
reportelement
x
=
"329"
y
=
"0"
width
=
"226"
height
=
"18"
/>
<
box
bottomPadding
=
"5"
>
<
pen
lineWidth
=
"1.0"
lineStyle
=
"Solid"
/>
<
toppen
lineWidth
=
"1.0"
lineStyle
=
"Solid"
/>
<
leftpen
lineWidth
=
"1.0"
lineStyle
=
"Solid"
/>
<
bottompen
lineWidth
=
"1.0"
lineStyle
=
"Solid"
/>
<
rightpen
lineWidth
=
"1.0"
lineStyle
=
"Solid"
/>
</
box
>
<
textelement
>
<
font
fontName
=
"細明體"
pdfFontName
=
"細明體"
pdfEncoding
=
"Identity-H"
isPdfEmbedded
=
"false"
/>
</
textElement
>
<
textfieldexpression
class
=
"java.lang.String"
>
<![CDATA[$F{HOWARD_CUSTOMER_ADDRESS}]]>
</
textFieldExpression
>
</
textField
>
</
band
>
</
detail
>
<
pagefooter
>
<
band
height
=
"21"
splitType
=
"Stretch"
>
<
textfield
>
<
reportelement
x
=
"205"
y
=
"0"
width
=
"80"
height
=
"20"
/>
<
textelement
textAlignment
=
"Right"
/>
<
textfieldexpression
class
=
"java.lang.String"
>
<![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]>
</
textFieldExpression
>
</
textField
>
<
textfield
evaluationTime
=
"Report"
>
<
reportelement
x
=
"285"
y
=
"0"
width
=
"40"
height
=
"20"
/>
<
textElement
/>
<
textfieldexpression
class
=
"java.lang.String"
>
<![CDATA[" " + $V{PAGE_NUMBER}]]>
</
textFieldExpression
>
</
textField
>
</
band
>
</
pageFooter
>
</
jasperReport
>
]]>
- JasperReports/iReport中,Text Field的字串長度過長,如何自動斷行(換行),避免值被截斷
- JasperReports IReport 中中文字体问题
- 一步一步学iReport + JasperReports(一) : 如何选择报表工具
- 一步一步学iReport + JasperReports(一) : 如何选择报表工具
- Jasperreports和iReport 的使用
- Jasperreports和iReport 的使用
- Jasperreports和iReport 的使用(整理)
- JasperReports+iReport+Hibernate+struts的使用
- JasperReports+iReport+Hibernate+struts的使用
- Jasperreports与iReport的结合使用
- JasperReports与iReport的问题解决方法
- iReport+JasperReports Server开发过程的Troubleshooting
- 一个简单的iReport + jasperReports例子
- 报表工具之JasperReports+iReport(1)
- 报表工具之JasperReports+iReport(2)
- 报表工具之JasperReports+iReport(3)
- 报表工具之JasperReports+iReport(4)
- 报表工具之JasperReports+iReport(5)
- 【ORACLE】ORA-01480:trailing null missing from STR bind value
- 为什么默认实参总是放在函数声明中
- 触发器创建示例
- HTML 样式&不赞成使用的标签和属性
- atoi函数实现
- JasperReports/iReport中,Text Field的字串長度過長,如何自動斷行(換行),避免值被截斷
- javascript eval和JSON之间的联系
- 浅谈用户体验背后的8个用户本能
- 程序员到底为了什么钻研技术?
- 一种集群Master节点选举算法
- DSP入门前的背景知识
- android安全问题(一) 静音拍照与被拍
- Linux-Load Average
- 35 个你也许不知道的 Google 开源项目