Total Pageviews

Showing posts with label iReport. Show all posts
Showing posts with label iReport. Show all posts

2015/11/19

[iReport] How to Set Line Break in Text Field

Problem
Here is my existing report design template:

You can see the report column is dynamic.
The report, with PDF format, is generating as following:

But our customer ask to set line break between 一般政府 and (基金或法人名稱).


How-To
1. Click the textfield

2. Set Markup property to styled
3. Java code should amend as bellows:
1
2
3
4
5
6
7
    Dbm037rVo header = new Dbm037rVo();
    header.setFundName("<style>公共公司<br />(基金或法人名稱)</style>");
    header.setRate1Year(Integer.toString(Integer.valueOf(accountYr) - 2).concat(" 年度(比率)"));
    header.setRate1Year(Integer.toString(Integer.valueOf(accountYr) - 1).concat(" 年度(比率)"));
    header.setRate1Year(accountYr.concat(" 年度(比率)"));
    
    result.add(header);


Reference
[1] http://www.tutorialspoint.com/jasper_reports/jasper_report_styles.htm

2015/11/03

[iReport] How to remove extra row and column when export to excel file

Problem
When I export report with excel format via iReport/JasperReports, the excel file always has extra blank row and extra blank column as following:

User asked to remove the unnecessary row and column. 

How-to
Add two properties to this jrxml file, and set to true

1
2
3
4
5
6
7
8
<?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/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="dbm506r1" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="d1c3bf81-aa19-4e0e-ad82-0a34f472e482">
 <property name="net.sf.jasperreports.export.xls.detect.cell.type" value="true"/>
 <property name="ireport.zoom" value="1.3310000000000004"/>
 <property name="ireport.x" value="0"/>
 <property name="ireport.y" value="0"/>
 <property name="net.sf.jasperreports.export.xls.remove.empty.space.between.columns" value="true"/>
 <property name="net.sf.jasperreports.export.xls.remove.empty.space.between.rows" value="true"/>

Check the result:



Reference
[1] http://stackoverflow.com/questions/8354126/ireport-jasperreports-extra-row-issue

2015/11/02

[iReport] How to format numeric data with Excel exporter

Problem
We use JasperReports API to export report with xls format.
But the problem is : data is numeric type, but in formula area its has been applied 1000 separator. It is String data type, no numeric data type.

We provide List of value object for this iReport file. The attributes of value object is as bellows (amount-related attributes' data type had been set to BigDecimal):
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
@Data
public class Dbm506rVo implements Serializable {
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    /** 年度 */
    private int year = 0;
    private String staYear = "";
    private BigDecimal gdp = BigDecimal.ZERO;
    private BigDecimal capitalAmount = BigDecimal.ZERO;
    private BigDecimal interestAmount = BigDecimal.ZERO;
    private BigDecimal yearExpend = BigDecimal.ZERO;
    private BigDecimal ttlAmt = BigDecimal.ZERO;
    private BigDecimal percentage1 = BigDecimal.ZERO;
    private BigDecimal percentage2 = BigDecimal.ZERO;
}


How-to
Set net.sf.jasperreports.export.xls.detect.cell.type to true (the default value is false) in this jrxml file.

Quote from document: Property whose value is used as default state of the IS_DETECT_CELL_TYPE export flag. Specifies whether the exporter should take into consideration the type of the original text field expressions and set the cell types and values accordingly.

1
2
3
4
5
6
<?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/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="dbm506r1" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="d1c3bf81-aa19-4e0e-ad82-0a34f472e482">
 <property name="net.sf.jasperreports.export.xls.detect.cell.type" value="true"/>
 <property name="ireport.zoom" value="1.3310000000000004"/>
 <property name="ireport.x" value="0"/>
 <property name="ireport.y" value="0"/>



The problem will be solved:

Reference
[1] http://stackoverflow.com/questions/10714709/jasperreports-how-to-format-numeric-data-with-excel-exporter

2015/08/24

[iReport] Custom Format

Problem
The original setting interest-related column in this report is as follows:

The value of interest-related column's show 5 decimal places:

But the foregoing report does not meet user's requirement. The digits to the right of the decimal point in a number determined by the data. If the value is 0.55000, show 0.55; if the value is 0.62690, show 0.6269. The correct report is as following:


Solution
Use custom format instead. The configuration is as bellows: 

2015/05/05

[iReport] Remove Pagination

Problem
I am using iReport as my report design tool. And export to excel report as bellows:

It apply pagination feature in excel file, so it reprint column header again. 
Therefore, we need to remove pagination in this report.

Solution
Click report in iReport

Check "ignore pagination" attribute

Check result

Reference
[1] http://jeffeske.com/blog/ireport-removing-pagination/

2015/04/20

Fail to set background color in iReport

Problem
Customer ask to set the background color of the last column to yellow.

But it does not work after I set backcolor to yellow.


Resolution
In addition to set background color, you also need to check Opaque attribute.

Then it will work now:



Reference
[1] http://community.jaspersoft.com/questions/817869/defining-color-band-background

2014/12/16

Utilize Styles to Change Font Color Based on Condition in iReport

Problem
Customer ask us to change font color to red if the amount is less than zero.

It should look like this:


Solution
  • Step1. Move cursor to "Styles" and right click => Add => Style


  • Step2. Right click on "style1" => Add "Conditional Style"


  • Step3. Edit "Conditional Expression" ( apply this style if $F(amount) value is less than zero)


  • Step4. Set font color to RED


  • Step5. Owning to set font color to red, it will set line color to red as well. Hence, we need to set line color to black manually.


  • Step6. Click on $F{amount} and set "Style" to "style1" which we create and configure in Step2 ~ Step5.



2014/07/11

[iReport] How to format text style in text field

Requirement
The first row in this report, the report name will be appended "總預算\n" before report name. And "總預算" should be bold font. 


Solution
Step 1. Set Text Field Expression

Step 2. Set properties Markup = styled for this text field.

Reference



[iReport] How to apply conditional formatting to your text fields

Requirement
In iReport, I wish to apply different formats to my text fields based on different conditions. For instance, when "融資項目別"== "特別預算" then the font should be bold font.

Solution
You can apply "Conditional Styles" to fulfill this requirement.
Step1. Add new Style

Step2. Add new Conditional Style

Step3. Edit Condition Expression

Step4. Set Bold attribute to be true

Step5. Select text fields and apply this style

Step6. Test


Reference
[1] http://community.jaspersoft.com/wiki/how-apply-conditional-formatting-your-text-fields

2014/07/01

net.sf.jasperreports.engine.JRException: org.xml.sax.SAXParseException; Premature end of file.

Problem
When I try to build my project, it show this error message
1:  [ERROR] Could not compile fms435r1.jrxml because org.xml.sax.SAXParseException; Premature end of file.  
2:  net.sf.jasperreports.engine.JRException: org.xml.sax.SAXParseException; Premature end of file.  
3:       at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:247)  
4:       at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:230)  
5:       at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:218)  
6:       at net.sf.jasperreports.engine.JasperCompileManager.compileToStream(JasperCompileManager.java:191)  
7:       at net.sf.jasperreports.engine.JasperCompileManager.compileReportToStream(JasperCompileManager.java:471)  
8:       at com.alexnederlof.jasperreport.CompileTask.call(CompileTask.java:65)  
9:       at com.alexnederlof.jasperreport.CompileTask.call(CompileTask.java:28)  
10:       at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)  
11:       at java.util.concurrent.FutureTask.run(FutureTask.java:166)  
12:       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)  
13:       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)  
14:       at java.lang.Thread.run(Thread.java:724)  

As I try to open this jrxml file via iReport Designer, it show the same error message


Root Cause
As I change iReport mode from Designer to XML, I figure out the root cause. This jrxml file had broken for unknown reason, it's an empty jrxml file so it cannot be compiled correctly.

THerefore, I need to revert this file to server version by svn client, and do it again.





2014/06/06

[iReport] How to adjust fileds' height dynamically

Problem
Here is my report template in iReport. I have 11 field elements in detail band. 

The "remarks field" may have more information need to show. Other fields' height need to increase based on "remark field's" height.

Solution
For each field, we need to set three attributes as bellows:
  • Position type: float
  • Stretch type: relative to tallest object
  • Stretch with overflow: true (checked)


Click detail band


Set split type to Prevent


See....the problem had been resolved.

Reference

2014/05/27

[iReport] Exported Excel Report But Has Missing Data

Problem
I am using iReport 5.5 in my project, the requirement is to use iReport to design report template, and export the report with pdf and xls format.
The problem is as I export pdf format, I can see complete data

but as I export xls format, the xls report has lost data in page header band.


Solution
The missing data problem results from the overlapping elements (even 1 pixel).

After I fixed the overlapping problems (add one more space between elements)

I can see complete data in xls report.