简体   繁体   English

Jasper Report文本案例使用

[英]Jasper Report text case using

We wants to use case statament like word case setting in jasper report. 我们想在Jasper报告中使用像单词大小写设置这样的大小写方法。 We have some sentences in our DB is uppercase and we want to change first character is upper and the other one is lowercase. 我们的数据库中有一些句子是大写的,我们要更改第一个字符为大写,而另一个则为小写。 How can we do it in jasper reports? 我们如何在碧玉报告中做到这一点?

Thank you. 谢谢。

When you design the report you put references to database fields somewhere on the page. 在设计报告时,您将引用放在页面上某处的数据库字段中。 When you open that for editing (right-click -> edit expression in iReport) what you really write is Java code returning a String, and reference like $F{SOMETHING} is a String type variable. 当您打开它进行编辑时(在iReport中右键单击-> edit expression ),您真正编写的是返回字符串的Java代码,而$F{SOMETHING}类的引用是String类型的变量。 Nothing prevents you from putting in some logic, like: 没有什么可以阻止您加入一些逻辑,例如:

$F{SOMETHING}.startsWith("A") ? "cool" : "not cool"

On the Jasper report designer; 在Jasper报表设计器上;

  1. Right click on the TextField for the sentence 右键单击该句子的TextField
  2. Click show properties 单击显示属性
  3. Next to the expression field open the expression editor 表达式字段旁边,打开表达式编辑器
  4. Input the below statement on the expression editor 表达式编辑器上输入以下语句

$F{some_field}.substring(0,1).toUpperCase()+$F{some_field}.substring(1,$F{some_field}.length()).toLowerCase()

For instance: the username's first letter is converted to uppercaps on the below expression. 例如:用户名的第一个字母在以下表达式上转换为大写。 For your case it will be sentence 对于你的情况将被判刑

例如,用户名的首字母转换为以下表达式的大写

  1. Press Finish Button to save, then run the report 按“ 完成”按钮保存,然后运行报告

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM