I am attempting to generate a cross tab report using JasperReports. The column contains time periods and the row contains different group by conditions. Now I need to change the styling of the row headers based on the level. For example, in the grid shown below, web and email need to be in bold while the other row headers are as is.
Now, I have a field in the bean that lets me decide if I should make the text bold or not, so I tried to use this in a conditional style as below
<style name="rowStyle" hAlign="Center">
<conditionalStyle>
<conditionExpression><![CDATA[$V{level}.intValue() != 0]]></conditionExpression>
<style isBold="true" hAlign="Left"/>
</conditionalStyle>
<conditionalStyle>
<conditionExpression><![CDATA[$V{level}.intValue() == 0]]></conditionExpression>
<style isBold="false" hAlign="Right"/>
</conditionalStyle>
</style>
and I have a field and a measure expression corresponding to this
<field name="level" class="java.lang.Integer"/>
<measure name="level" class="java.lang.Integer">
<measureExpression><![CDATA[$F{level}]]></measureExpression>
</measure>
However this style does nothing when used inside the crosstabRowHeader, it takes effect only inside crosstabCell.
So my questions are
Is anyway for me to use a conditional style inside the crosstabRowHeader?
More specifically, can I access any bean property within the crosstabRowHeader?
Managed to figure this out after all.
So the issue is to be able to access a property from the bean within the crosstabrowheader (or any other cross tab headers).
To do this first create a field corresponding to the bean as so -
<field name="voBean" class="com.jasper.reports.voBean">
<fieldDescription>_THIS</fieldDescription>
</field>
Then in the headers, specify this bean as the bucket class.
<rowGroup name="voBean" width="200">
<bucket class="com.jasper.reports.voBean">
<bucketExpression><![CDATA[$F{voBean}]]></bucketExpression>
</bucket>
You can now start to access any property on the bean as below
<textFieldExpression><![CDATA[$V{voBean}.getRowName()]]></textFieldExpression>
Hope this helps anybody else with the same problem.
Related
I am using TIBCO Jaspersoft Studio-6.2.0.final for generating report . I am able to generate report in word (.docx).
I added some sample text. In export word sample text shown inside a frame. But when I am trying to update or add any extra text into that report in word, its hiding inside the frame. When I expand that frame, then it showing.
How I can generate report in word without any frame like normal word? So that I can add any text, so it will show normally.
Below I added jrxml code.
<queryString>
<![CDATA[SELECT 1 FROM DUal]]>
</queryString>
<field name="1" class="java.math.BigDecimal"/>
<detail>
<band height="20" splitType="Stretch">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="0" y="1" width="510" height="19" uuid="68ec5b9f-416e-45d6-b2aa-4d1f31a08250">
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
</reportElement>
<textElement>
<font fontName="Arial" size="11"/>
</textElement>
<textFieldExpression><![CDATA["This is the sample text for testing.To test in word"]]></textFieldExpression>
</textField>
</band>
</detail>
Update:
Is any one having any update on this?
Currently there is no possibility to generate paragraph-oriented docx content. The built-in .docx exporter is a grid-layout exporter, so it will generate a table-based document. This is why enclosing frames/table cells are present in the document. Even if you'd use a single huge textfield for your entire document, a table with a single cell will be generated as docx output.
The only way to get the desired behavior is to implement and use a custom paragraph-oriented docx exporter, based on existing JasperReports APIs.
I hope this helps.
Jasper export .docx as grid/table. In your exported document use Layout -> View Gridlines to show those tables. You can edit them manually if it's a single report what you need. Else, check Aspose library or try to implement manually a custom exporter.
If your only problem is that fields doesn't expand when you write, just add this code to your report properties:
<property name="net.sf.jasperreports.export.docx.flexible.row.height" value="true"/>
In a jasper report I use a JSON datasource.
This datasource contains numbers (e.g. 159.994).
There is a field of class java.lang.double (let's call it "doubleField") and a text field with this field and a pattern ("#,##0.00 ¤ (brutto)").
The pattern works fine (german currency format) but if I print out just the value of the doubleField the expected output would be "195,99" or "159.994".
But in fact it is "159.994,00" or "159994.0".
There was a solution changing the language of the report from "groovy" to "JavaScript" but this won't help and is also not applicable.
There is a "quick&dirty" solution (without being quick) to just take the JSON value as a String and then cast it to a double in the text field. This works fine but it's dirty and not really quick.
Any ideas?
I have a Jasper report definition. I'm just including a few things from that report definition that I think might be relevant to your problem.
First, I have several field definitions. Here are two of them:
<field name="FundFixedBeginningBalance" class="java.lang.Double">
<fieldDescription>
<![CDATA[FundFixedBeginningBalance/FundFixedBeginningBalanceValue]]>
</fieldDescription>
</field>
<field name="FundNonFixedBeginningBalance" class="java.lang.Double">
<fieldDescription>
<![CDATA[FundNonFixedBeginningBalance/FundNonFixedBeginningBalanceValue]]>
</fieldDescription>
</field>
Note how both are defined with class="java.lang.Double". I'm using XPath expressions because my data is in XML, but that is not fundamentally different from JSON. Later, in the report layout section I have:
<textField pattern="#,##0.00 ;(#,##0.00)" isBlankWhenNull="true">
<reportElement positionType="Float" x="368" y="52" width="100" height="14" uuid="deac984d-39b8-49f4-b4d2-28e66681c098">
<property name="local_mesure_unitx" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
</reportElement>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA[$F{FundFixedBeginningBalance} + $F{FundNonFixedBeginningBalance}]]></textFieldExpression>
</textField>
Notice there is no casting within the textFieldExpression element; just substituting both fields in with $F and adding them together (and this prints correctly). Are you doing something different?
I have a Jasper report with a Pie Chart that is being drawn at the group_footer for my group "contract". The contract group is returning two rows at this time and I am using the contract id which are integers 1 and 3. When I print the contract id in the group_footer, it prints 1 and then 3 as expected. However, when I try and pass the same contract id into a datasetrun for the Pie Chart in the very same group_footer, the value being passed into the parameter is 3 for both charts (I am viewing the SQL using statement logging on the db server). I can not figure out how it's sending the second value "3" both times. As I mentioned, the contract id prints on the report right next to the chart as "1" the first item in the group.
Here is my subDataset with the parameter "currentContractId":
<subDataset name="age_stats" uuid="44847f01-474b-4228-96e9-ea5ab992f67b">
<property name="....data.defaultdataadapter" value="database"/>
<parameter name="currentContractId" class="...Integer" isForPrompting="false"/>
<queryString>
<![CDATA[SELECT * FROM table WHERE column = $P{currentContractId}]]>
</queryString>
<field name="age" class="java.lang.String"/>
<field name="count" class="java.lang.Long"/>
</subDataset>
Here is the chart datasetrun where I am trying to pass the field "id" into the "currentContractId" parameter for my subDataset above:
<pieDataset maxCount="6">
<dataset>
<datasetRun subDataset="age_stats" uuid="75d14f7c-f94e-4749-860f-ea95c2134e9c">
<datasetParameter name="currentContractId">
<datasetParameterExpression><![CDATA[$F{id}]]></datasetParameterExpression>
</datasetParameter>
</datasetRun>
</dataset>
</pieDataset>
I am happy to provide the full jrxml to anyone who thinks it would be helpful.
I found the problem. Aside from the options in the chart dataset wizard, there is a seperate option under the chart properties called "Evaluation Time". I set the Evaluation Time option to my Group "contract" and the problem was resolved.
Have anyone tried to import user defined classes in jasper report (.jrxml file)?
I want to use some (user defined) Util class inside my jasper report to cook some bean attributes. I am using Javabean datasource
Please let me know if you need further clarification.
syntax to import class is
<import value="java.util.HashMap"/>
I want to use
<import value="mypackage.MyUtil" />
....
....
<field name="myVar" class="java.lang.String">
<fieldDescription><![CDATA[MyUtil.cook(myData)]]>
</fieldDescription>
</field>
The simple definition for MyUtil.java could be
package mypackage;
public class MyUtil
{
public static String cook(String data)
{
return data + "_cooked";
}
}
I think I should have tried sufficiently before asking this.
There is nothing extra needed apart from
There are two sections in jrxml:
1. Defining fields from javabean source
2. Using fields defined in step 1. to populate values in detail band
I was trying to cook the value of javabean members even before they are used to create fields
So, jasper was trying to parse that 'expression' as javabean member.
Following is wrong
<field name="myVar" class="java.lang.String">
<fieldDescription><![CDATA[MyUtil.cook(myData)]]>
</fieldDescription>
</field>
When I used the Util class on field value, it worked.
<textField>
<reportElement x="200" y="0" width="100" height="13"/>
<textElement/>
<textFieldExpression class="java.lang.String">
<![CDATA[MyUtil.cook($F{myVar})]]>
</textFieldExpression>
</textField>
Thanks
Nayn
You have to set the classpath in your iReport. It depends on its version, but is generally under Settings/Classpath
I'm working on a system that includes a large number of reports, generated using JasperReports. One of the newer features is that you can define styles for reports.
From the available docs I believe there is some way to have an external file defining styles to use, and you can reference that in your jasper reports. This allows a single style to be used by multiple reports.
I can't find any concrete information on whether this is an actual feature, and if it is, how to use it. Does anyone know if it is possible to have external styles for jasper reports, and if so, how to do it?
Use JasperReport templates. A JasperReports template is one that ends in .jrtx, and may look similar to this (styles.jrtx):
<?xml version="1.0"?>
<!DOCTYPE jasperTemplate
PUBLIC "-//JasperReports//DTD Template//EN"
"http://jasperreports.sourceforge.net/dtds/jaspertemplate.dtd">
<jasperTemplate>
<style name="Report Title" isDefault="false" hAlign="Center" fontSize="24" isBold="true"/>
<style name="Heading 1" isDefault="false" fontSize="18" isBold="true"/>
<style name="Heading 2" isDefault="false" fontSize="14" isBold="true"/>
</jasperTemplate>
and then in your .jrxml file, include it as a template:
...
<template><![CDATA["styles.jrtx"]]></template>
...
iReport also understands this, so your styles are imported and shown in iReport correctly (though I did notice sometimes it wouldn't pick them up an a reload or recompile was necessary).
You can also avoid specifying the actual file name in the <template> element by using a parameter passed into your report at runtime
<parameter name="TEMPLATE_FILE" isForPrompting="false" class="java.lang.String"/>
<template><![CDATA[$P{TEMPLATE_FILE}]]></template>
where $P{TEMPLATE_FILE} is the full path to the style resource
I like to share my learning of using styles in Jasper reports, which I think quite useful for report designers like me, from a book named JasperReport Development cookbook by Bilal Siddiqui. I like this book and found demonstrating styles in a variety of manner like:
Creating a reusable style
Simply select “Style” while creating a new report and define style for text, line and rectangles. The style file will be stored as .jrtx file.
Import reusable style it in your report
There are three chunk of information when importing styles in your report.
Step1. Name and location of style template
<template><![CDATA["C:\\ BigBoldRedTemplate.jrtx"]]></template>
Step2. Each time you apply style to your report elements using the style template, a <reportElement> tag is created as shown below:
//style applied to a rectangle
<rectangle radius="10">
<reportElement style="BigBoldRed" mode="Transparent" x="0" y="0" width="555" height="44"/>
</rectangle>
//style applied to a the text field
<staticText>
<reportElement style="BigBoldRed" x="0" y="0" width="555" height="66"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Monthly Customer Invoices]]></text>
</staticText>
Mixing the internal and reusable styles in report
Using the power of HTML to style your report
For example, your text field has following expression which includes HTML tags (i.e. <li>) and you want the HTML tags to work in your report design:
"<li>"+"Invoice # "+$F{InvoiceID}+", "+
$F{CustomerName}+" purchased
"+$F{ProductName}+" in
"+$F{InvoicePeriod}+" (Invoice value:
\$ "+$F{InvoiceValue}+")"+"
Solution is simple, just set “Markup” property of the text field to “Styled” and that it.
I have taken permission from the author to copy code chunk from his JasperReports cookbook in this post.