I am using iReport 5.6 and when I set conditional formatting for cells in a table preview in iReport works ok
When I save as xls document the table is shown the cells are colored and values are in the cells but they (values) are not displayed. If I set cell color to normal I can see the values. Any ideas how to fix it. Either in Excel or iReport (preferably)?
my xml
<?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="test_tabelegrafi" language="groovy" 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="92"/>
<style name="table" lineSpacing="Single">
<box>
<pen lineWidth="1.0" lineColor="#000000"/>
</box>
</style>
<style name="table_TH" mode="Opaque" backcolor="#F0F8FF" lineSpacing="Single">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table_CH" mode="Opaque" backcolor="#BFE1FF" lineSpacing="Single">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table_TD" mode="Opaque" backcolor="#FFFFFF" lineSpacing="Single">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="barva_rdeca" mode="Transparent" forecolor="#000000" backcolor="#FFFFFF" lineSpacing="Single" pattern="">
<conditionalStyle>
<conditionExpression><![CDATA[$F{count} > 100]]></conditionExpression>
<style mode="Opaque" backcolor="#FF0000" fill="Solid" lineSpacing="Single"/>
</conditionalStyle>
<conditionalStyle>
<conditionExpression><![CDATA[$F{count} <= 100]]></conditionExpression>
<style mode="Opaque" backcolor="#00CC33" fill="Solid" lineSpacing="Single"/>
</conditionalStyle>
</style>
<subDataset name="New Dataset 2">
<queryString>
<![CDATA[select
o_teacher,
o_class,
o_location,
count(*)
from outputs_txt
where o_date between '2014-05-30' and '2014-06-30' and o_class != '' and o_location is not null
group by o_teacher, o_class,o_location
order by o_class,o_teacher
limit 10]]>
</queryString>
<field name="o_teacher" class="java.lang.String"/>
<field name="o_class" class="java.lang.String"/>
<field name="o_location" class="java.lang.String"/>
<field name="count" class="java.lang.Long"/>
</subDataset>
<subDataset name="Graf">
<queryString>
<![CDATA[select
o_teacher,
o_class,
o_location,
count(*)
from outputs_txt
where o_date between '2014-05-30' and '2014-06-30' and o_class != '' and o_location is not null
and o_location IN ('tel1','tel2', 'tel3')
group by o_teacher, o_class,o_location
order by o_class,o_teacher
limit 10]]>
</queryString>
<field name="o_teacher" class="java.lang.String"/>
<field name="o_class" class="java.lang.String"/>
<field name="o_location" class="java.lang.String"/>
<field name="count" class="java.lang.Long"/>
</subDataset>
<queryString>
<![CDATA[select
o_teacher,
o_class,
o_location,
count(*)
from outputs_txt
where o_date between '2014-05-30' and '2014-06-30' and o_class != '' and o_location is not null
group by o_teacher, o_class,o_location
order by o_class,o_teacher
limit 10]]>
</queryString>
<field name="o_teacher" class="java.lang.String"/>
<field name="o_class" class="java.lang.String"/>
<field name="o_location" class="java.lang.String"/>
<field name="count" class="java.lang.Long"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch">
<staticText>
<reportElement x="154" y="0" width="234" height="38"/>
<textElement textAlignment="Center" lineSpacing="Single">
<font size="14"/>
</textElement>
<text><![CDATA[TESTNI REPORT TABEL IN GRAFOV]]></text>
</staticText>
</band>
</title>
<pageHeader>
<band height="287" splitType="Stretch">
<componentElement>
<reportElement key="table" style="barva_rdeca" stretchType="RelativeToBandHeight" x="0" y="0" width="555" height="118"/>
<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
<datasetRun subDataset="New Dataset 2">
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
</datasetRun>
<jr:column width="90">
<jr:columnHeader style="table_CH" height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="90" height="30"/>
<textElement lineSpacing="Single"/>
<text><![CDATA[o_teacher]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="table_TD" height="20" rowSpan="1">
<textField>
<reportElement x="0" y="0" width="90" height="20"/>
<textElement lineSpacing="Single"/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{o_teacher}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="90">
<jr:columnHeader style="table_CH" height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="90" height="30"/>
<textElement lineSpacing="Single"/>
<text><![CDATA[o_class]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="table_TD" height="20" rowSpan="1">
<textField>
<reportElement x="0" y="0" width="90" height="20"/>
<textElement textAlignment="Center" lineSpacing="Single"/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{o_class}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="90">
<jr:columnHeader style="table_CH" height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="90" height="30"/>
<textElement lineSpacing="Single"/>
<text><![CDATA[o_location]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="table_TD" height="20" rowSpan="1">
<textField>
<reportElement x="0" y="0" width="90" height="20"/>
<textElement textAlignment="Center" lineSpacing="Single"/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{o_location}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="90">
<jr:columnHeader style="table_CH" height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="90" height="30"/>
<textElement lineSpacing="Single"/>
<text><![CDATA[count]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="table_TD" height="20" rowSpan="1">
<textField>
<reportElement style="barva_rdeca" x="0" y="0" width="90" height="20"/>
<textElement textAlignment="Center" lineSpacing="Single" markup="none"/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{count}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
<bar3DChart>
<chart>
<reportElement positionType="Float" x="0" y="141" width="555" height="146"/>
<chartTitle/>
<chartSubtitle/>
<chartLegend/>
</chart>
<categoryDataset>
<dataset>
<datasetRun subDataset="Graf">
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
</datasetRun>
</dataset>
<categorySeries>
<seriesExpression><![CDATA[$F{o_location}]]></seriesExpression>
<categoryExpression><![CDATA[$F{o_teacher}]]></categoryExpression>
<valueExpression><![CDATA[$F{count}]]></valueExpression>
</categorySeries>
</categoryDataset>
<bar3DPlot>
<plot/>
<itemLabel/>
<categoryAxisFormat>
<axisFormat/>
</categoryAxisFormat>
<valueAxisFormat>
<axisFormat/>
</valueAxisFormat>
</bar3DPlot>
</bar3DChart>
</band>
</pageHeader>
<columnHeader>
<band splitType="Stretch"/>
</columnHeader>
<detail>
<band splitType="Stretch"/>
</detail>
<columnFooter>
<band splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
The only solution I could find was that after export I selected the cells in Excel and changed type to Numeric or smth other then custom.
Related
This question already has answers here:
how to display decimal precision value in jasper report 4.0.2
(4 answers)
formatting a string to a currency format in jasper report
(8 answers)
Number Formatting in iReport
(2 answers)
Closed 7 months ago.
I have a task to generate PDFs with nodeJS, so i am working with the node-jasper library.
I want to display a table component that contains float numbers but when i send dataset from back-end, it shows only the integer part of the numbers.
Here is my nodjs code:
const express = require('express')
const app = express()
const port = 5000
var jasper = require('node-jasper')({
path: './lib/jasperreports-6.10.0',
reports: {
report: {
jasper: './jasperFiles/table.jasper',
jrxml: './jrxmlFiles/table.jrxml',
conn: 'in_memory_json'
}
},
});
app.get('/get_table', (req, res) => {
var report = {
report: 'report',
data: {
list: jasper.toJsonDataSource(
{
data: [
{
id: 1,
val: 2.55
},
{
id: 2,
val: 3.85
}
]
},
'data'
),
}
,
dataset: {}
}
var pdf = jasper.pdf(report);
res.set({
'Content-type': 'application/pdf',
'Content-Length': pdf.length
});
res.send(pdf)
});
app.listen(port, () => {
console.log('app is runing on port: ', port)
})
here is my jrxml file:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.10.0.final using JasperReports Library version 6.10.0-unknown -->
<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="table" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="ea493b18-9fb4-4bab-bdfd-323454e90b99">
<style name="Table_CH" mode="Opaque" backcolor="#BFE1FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Table_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<subDataset name="Dataset1" uuid="586aa694-4896-425f-b58c-8fceeeb4d3f0">
<field name="val" class="java.lang.Double"/>
<field name="id" class="java.lang.Integer"/>
</subDataset>
<parameter name="list" class="net.sf.jasperreports.engine.JRDataSource"/>
<detail>
<band height="274" splitType="Stretch">
<componentElement>
<reportElement x="110" y="20" width="200" height="200" uuid="e63d85ed-faa4-4983-a00b-35c18d4e34bf">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
</reportElement>
<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
<datasetRun subDataset="Dataset1" uuid="b4c72650-c463-434c-9f7a-c34037079fd7">
<dataSourceExpression><![CDATA[$P{list}]]></dataSourceExpression>
</datasetRun>
<jr:column width="100" uuid="84d356bb-f8fd-4276-8902-42df76c454ec">
<jr:columnHeader style="Table_CH" height="30">
<staticText>
<reportElement x="0" y="0" width="100" height="30" uuid="7e3d4e8d-23ff-4ecc-b0d4-0081e04262f9"/>
<text><![CDATA[val]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table_TD" height="30">
<textField>
<reportElement x="0" y="0" width="100" height="30" uuid="1392a46d-0fd3-451f-9886-09bbf77894cf"/>
<textFieldExpression><![CDATA[$F{val}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="100" uuid="d86214ca-1b51-41fd-a7dd-41c2309a99dc">
<jr:columnHeader style="Table_CH" height="30">
<staticText>
<reportElement x="0" y="0" width="100" height="30" uuid="b22794ae-8852-41f7-9e9c-366c15efa91b"/>
<text><![CDATA[id]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table_TD" height="30">
<textField>
<reportElement x="0" y="0" width="100" height="30" uuid="720d1524-19cc-473a-9620-083a9575ac47"/>
<textFieldExpression><![CDATA[$F{id}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</detail>
</jasperReport>
Here is the resulted report:
I set double type to 'val' column. But as you can see the 'val' column contain the numbers with 0 in the fractional part.
I am printing PDF report using Jasper Report. When data overflow and new page is being generated I get border layout corruption - a right border a bit bigger than left one (take a look at the picture).
Actually it's really weird behavior and I don't understand what I am doing wrong.
my jrxml file:
<band height="70">
<staticText>
<reportElement uuid="c5529319-8868-4c4f-a68c-36f6ce79d652" x="0" y="0" width="555" height="20" forecolor="#000000"/>
<textElement textAlignment="Center" markup="none">
<font size="15" isBold="true"/>
</textElement>
<text><![CDATA[TEST DATA]]></text>
</staticText>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement uuid="bcea9da4-49d2-498a-aefc-40ebfb747183" positionType="Float" stretchType="RelativeToTallestObject" x="216" y="50" width="339" height="20"/>
<box>
<pen lineWidth="0.25"/>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement>
<font size="13"/>
</textElement>
<textFieldExpression><![CDATA[$F{title}]]></textFieldExpression>
</textField>
<staticText>
<reportElement uuid="91766db1-a506-4115-b31a-b8499ef306c9" positionType="Float" x="0" y="30" width="555" height="20"/>
<textElement>
<font size="13" isBold="true" isItalic="true"/>
</textElement>
<text><![CDATA[Test Title]]></text>
</staticText>
<textField isStretchWithOverflow="true">
<reportElement uuid="f2898317-cfda-4e91-b52b-95da97d80d49" positionType="Float" stretchType="RelativeToTallestObject" x="0" y="50" width="216" height="20" forecolor="#000000"/>
<box>
<pen lineWidth="0.25"/>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Left" markup="none">
<font size="13" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA["First row"]]></textFieldExpression>
</textField>
</band>
<band height="40">
<elementGroup>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement uuid="232505af-9176-4cd3-ae46-18184e3dc468" positionType="Float" stretchType="RelativeToTallestObject" x="216" y="0" width="339" height="40"/>
<box>
<pen lineWidth="0.25"/>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement>
<font size="13"/>
</textElement>
<textFieldExpression><![CDATA[$F{second}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement uuid="a6e45bfc-9c09-4db8-8cc0-2fabfedf7653" positionType="Float" stretchType="RelativeToTallestObject" x="0" y="0" width="216" height="40" isPrintWhenDetailOverflows="true" forecolor="#000000"/>
<box>
<pen lineWidth="0.25"/>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Left" markup="none">
<font size="13" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA["Second row"]]></textFieldExpression>
</textField>
</elementGroup>
</band>
<band height="40" splitType="Stretch">
<staticText>
<reportElement uuid="1ae02b52-e3d7-4a4a-b805-e656f8734a49" stretchType="RelativeToTallestObject" x="216" y="0" width="339" height="40" isPrintWhenDetailOverflows="true"/>
<box>
<pen lineWidth="0.25"/>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement/>
<text><![CDATA[]]></text>
</staticText>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement uuid="232505af-9176-4cd3-ae46-18184e3dc468" stretchType="RelativeToTallestObject" isPrintRepeatedValues="false" x="216" y="0" width="339" height="40"/>
<box>
<pen lineWidth="0.25"/>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement>
<font size="13"/>
</textElement>
<textFieldExpression><![CDATA[($F{third} == null) ? "" :
($F{third} ? "Yes" : "No")]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement uuid="a6e45bfc-9c09-4db8-8cc0-2fabfedf7653" positionType="Float" stretchType="RelativeToTallestObject" isPrintRepeatedValues="false" x="0" y="0" width="216" height="40" forecolor="#000000"/>
<box>
<pen lineWidth="0.25"/>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Left" markup="none">
<font size="13" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA["Third row Third row Third row Third row Third row Third row Third row Third row Third rowThird row Third row Third row Third row Third rowThird rowThird rowThird row Third row Third row "]]></textFieldExpression>
</textField>
</band>
<band height="40">
<elementGroup>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement uuid="232505af-9176-4cd3-ae46-18184e3dc468" positionType="Float" stretchType="RelativeToTallestObject" isPrintRepeatedValues="false" x="216" y="0" width="339" height="40" isPrintWhenDetailOverflows="true"/>
<box>
<pen lineWidth="0.25"/>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement>
<font size="13"/>
</textElement>
<textFieldExpression><![CDATA[($F{fourth} == null) ? "" :
($F{fourth} ? "Yes" : "No")]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement uuid="a6e45bfc-9c09-4db8-8cc0-2fabfedf7653" positionType="Float" stretchType="RelativeToTallestObject" x="0" y="0" width="216" height="40" forecolor="#000000"/>
<box>
<pen lineWidth="0.25"/>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Left" markup="none">
<font size="13" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA["Fourth row Fourth row Fourth row Fourth row Fourth row Fourth row"]]></textFieldExpression>
</textField>
</elementGroup>
</band>
<band height="70">
<elementGroup>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement uuid="93cd5464-2924-4403-8677-64558418afa1" positionType="Float" stretchType="RelativeToTallestObject" x="0" y="0" width="216" height="40" forecolor="#000000"/>
<box>
<pen lineWidth="0.25"/>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Left" markup="none">
<font size="13" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA["Fiveth row Fiveth row Fiveth row Fiveth row Fiveth row Fiveth row"]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement uuid="4bf32279-7361-4d05-b652-e37e7f4c96ba" positionType="Float" stretchType="RelativeToTallestObject" x="216" y="0" width="339" height="40"/>
<box>
<pen lineWidth="0.25"/>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement>
<font size="13"/>
</textElement>
<textFieldExpression><![CDATA[$F{fiveth}]]></textFieldExpression>
</textField>
</elementGroup>
</band>
I manage to reproduce your problem and as I see it is a bug (including fields in frame and/or setting stretchType="RelativeToBandHeight" did not solve the problem).
The workaround that I can see is to remove all borders from textField except right border on first field and include the fields in a frame with border.
<frame borderSplitType="DrawBorders">
<reportElement x="0" y="0" width="555" height="40" uuid="d2be3f0d-da65-4a09-b9c1-9d85c2f0af39">
</reportElement>
<box>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement positionType="Float" stretchType="RelativeToTallestObject" x="0" y="0" width="216" height="40" forecolor="#000000" uuid="a6e45bfc-9c09-4db8-8cc0-2fabfedf7653"/>
<box>
<pen lineWidth="0.25"/>
<topPen lineWidth="0.0"/>
<leftPen lineWidth="0.0"/>
<bottomPen lineWidth="0.0"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Left" markup="none">
<font size="13" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA["Third row Third row Third row Third row Third row Third row Third row Third row Third rowThird row Third row Third row Third row Third rowThird rowThird rowThird row Third row Third row "]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement stretchType="RelativeToTallestObject" x="216" y="0" width="339" height="40" uuid="232505af-9176-4cd3-ae46-18184e3dc468"/>
<textElement>
<font size="13"/>
</textElement>
<textFieldExpression><![CDATA[($P{third} == null) ? "" :($P{third} ? "Yes" : "No")]]></textFieldExpression>
</textField>
</frame>
The attribute borderSplitType="DrawBorders" on frame define whether to print or not print the bottom/top border of when split on new page
Recently, I had to export some reports using JasperReports under ods /xls format.
The export works fine but I didn't manage to find a way to add some excel formulas between the exported columns (let's simplify it by saying a sum of some columns as described below).
When user modifies the column A in the excel file, column C gets modified (basic excel formulas, nothing new...)
Based on some comments and answers here is what I've done
<detail>
<band height="134" splitType="Stretch">
<componentElement>
<reportElement x="-20" y="0" width="120" height="60" uuid="884b6c49-9006-464d-982e-e2a5f2cb3e3e">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
</reportElement>
<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
<datasetRun subDataset="Empty Dataset1" uuid="b60c3bee-0624-4a6a-bbb1-e706521c0a9a">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource(java.util.Arrays.asList($F{dto}.getNbLgtA()))]]></dataSourceExpression>
</datasetRun>
<jr:column width="40" uuid="1dbb56d0-f25f-410b-9e02-d08b7fe84388">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Colonne1"/>
<jr:tableHeader height="30">
<staticText>
<reportElement x="0" y="0" width="40" height="30" uuid="ff8f394e-39ea-4d08-898f-601e92e6d1f3"/>
<text><![CDATA[A]]></text>
</staticText>
</jr:tableHeader>
<jr:detailCell height="30">
<staticText>
<reportElement x="0" y="0" width="40" height="30" uuid="c0c2b023-2d00-4080-88a3-a73f19fe9cda"/>
<text><![CDATA[1]]></text>
</staticText>
</jr:detailCell>
</jr:column>
<jr:column width="40" uuid="33f41b08-3d77-4076-9712-9514211dd3af">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Colonne2"/>
<jr:tableHeader height="30">
<staticText>
<reportElement x="0" y="0" width="40" height="30" uuid="ad2b74aa-95bf-43d7-83a4-6528f344b410"/>
<text><![CDATA[B]]></text>
</staticText>
</jr:tableHeader>
<jr:detailCell height="30">
<staticText>
<reportElement x="0" y="0" width="40" height="30" uuid="6d121f9e-e92d-45ba-9a48-82bf8b1245e0"/>
<text><![CDATA[2]]></text>
</staticText>
</jr:detailCell>
</jr:column>
<jr:column width="40" uuid="42d367d1-2be7-46bf-838b-ba4c1c6f3399">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Colonne3"/>
<jr:tableHeader height="30">
<staticText>
<reportElement x="0" y="0" width="40" height="30" uuid="63e3dd54-0297-463f-b061-4c536baf62a8"/>
<text><![CDATA[C]]></text>
</staticText>
</jr:tableHeader>
<jr:detailCell height="30">
<property name="net.sf.jasperreports.export.xls.formula" value="SUM(A2, B2)"/>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</detail>
But it doesn't work.
Here you could find some useful information about using Excel formulas:
http://jasperreports.sourceforge.net/sample.reference/xlsformula/index.html#xlsformula
For instance, below is an example of using SUM formula (the expression should be enclosed within quotes):
<propertyExpression name="net.sf.jasperreports.export.xls.formula">
<![CDATA["SUM(A1,B1)"]]>
</propertyExpression>
You need to ensure that isDetectCellType property is set to true for your report in order to make a formula to work.
A complete working example (using an empty datasource) is the following:
<detail>
<band height="134" splitType="Stretch">
<componentElement>
<reportElement x="-20" y="0" width="120" height="60" uuid="884b6c49-9006-464d-982e-e2a5f2cb3e3e">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
</reportElement>
<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
<datasetRun subDataset="Empty Dataset1" uuid="b60c3bee-0624-4a6a-bbb1-e706521c0a9a">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource()]]></dataSourceExpression>
</datasetRun>
<jr:column width="40" uuid="1dbb56d0-f25f-410b-9e02-d08b7fe84388">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Colonne1"/>
<jr:tableHeader height="30">
<staticText>
<reportElement x="0" y="0" width="40" height="30" uuid="ff8f394e-39ea-4d08-898f-601e92e6d1f3"/>
<text><![CDATA[A]]></text>
</staticText>
</jr:tableHeader>
<jr:detailCell height="30">
<textField pattern="">
<reportElement x="0" y="0" width="40" height="30" uuid="b989d9e8-64d8-467f-a8a0-7b92a1746a0d"/>
<textFieldExpression><![CDATA[1]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="40" uuid="33f41b08-3d77-4076-9712-9514211dd3af">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Colonne2"/>
<jr:tableHeader height="30">
<staticText>
<reportElement x="0" y="0" width="40" height="30" uuid="ad2b74aa-95bf-43d7-83a4-6528f344b410"/>
<text><![CDATA[B]]></text>
</staticText>
</jr:tableHeader>
<jr:detailCell height="30">
<textField pattern="">
<reportElement x="0" y="0" width="40" height="30" uuid="3448c5dc-f887-415d-9833-4a22ea5b06c8"/>
<textFieldExpression><![CDATA[2]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="40" uuid="42d367d1-2be7-46bf-838b-ba4c1c6f3399">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Colonne3"/>
<jr:tableHeader height="30">
<staticText>
<reportElement x="0" y="0" width="40" height="30" uuid="63e3dd54-0297-463f-b061-4c536baf62a8"/>
<text><![CDATA[C]]></text>
</staticText>
</jr:tableHeader>
<jr:detailCell height="30">
<textField pattern="">
<reportElement x="0" y="0" width="40" height="30" uuid="63e3ed54-0567-463f-b0c1-4c676baf62a8">
<propertyExpression name="net.sf.jasperreports.export.xls.formula"><![CDATA["SUM(A" +($V{PAGE_COUNT}+2) + ",B" + ($V{PAGE_COUNT}+2) +")"]]></propertyExpression>
</reportElement>
<textFieldExpression><![CDATA[3]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</detail>
I've used an Excel file as datasource for building report with iReport. The xls file contains dates yyyy-MM-dd format.
I've set the Date field class to java.sql.Date and I click on preview in iReport. There is an error: Unable to get value for field 'Date' of class 'java.sql.Date'.
I have tried with java.util.Date too. Do you have any ideas?
It is quite simple.
I've xls file (birhdays.xls) like this:
The datasource definition (in iReport) is:
As you can see from the image above I've set yyyy-MM-dd format for date field in DS definition.
The date field definition in jrxml file:
<field name="Birthday" class="java.util.Date"/>
The full jrxml file:
<?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="excel_ds" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="b0f82d57-325b-4c30-b635-f464851e0a47">
<queryString>
<![CDATA[]]>
</queryString>
<field name="Name" class="java.lang.String"/>
<field name="Birthday" class="java.util.Date"/>
<columnHeader>
<band height="20" splitType="Stretch">
<staticText>
<reportElement uuid="cd75f6d9-1781-4938-bf24-178b6663bcd1" x="0" y="0" width="147" height="20"/>
<box leftPadding="10">
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font isBold="true" isItalic="true"/>
</textElement>
<text><![CDATA[Name]]></text>
</staticText>
<staticText>
<reportElement uuid="5d4c21f1-9afd-40c7-ade0-6fcc0b3d8373" x="147" y="0" width="100" height="20"/>
<box leftPadding="10">
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font isBold="true" isItalic="true"/>
</textElement>
<text><![CDATA[Birthday]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="20" splitType="Stretch">
<textField>
<reportElement uuid="82f5a338-ef5d-4838-8cd0-c2544af3a73d" x="0" y="0" width="147" height="20"/>
<box leftPadding="10">
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$F{Name}]]></textFieldExpression>
</textField>
<textField pattern="dd/MM/yyyy">
<reportElement uuid="e6eb6f83-b8f3-42fd-b116-02db2322b6a5" x="147" y="0" width="100" height="20"/>
<box leftPadding="10">
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$F{Birthday}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
And the result will be (via preview in iReport):
Note:
I've used iReport 5.1.0
I am new to Jasper Reports and iReports that I am using to design the reports.
I am currently designing a report in iReport and want to export it in excel (xls). Here is the screen shot of what I want to design and the second screen is what I am getting.
Shot at 2012-08-04
Here is what I have managed to get. As you can see there are many problems in the output.
Column A is missing
There are some problems with column D and E and Column C is also invisible.
I dont know how to add blank rows in my design from IReports
Shot at 2012-08-04
Here is the source to what I have done so far:
<?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="report1" language="groovy" pageWidth="792" pageHeight="612" orientation="Landscape" columnWidth="792" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="1e5ee76a-b072-4f31-a1ce-d0c921d2ce55">
<property name="ireport.zoom" value="1.0"/>
<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.detect.cell.type" value="true"/>
<property name="net.sf.jasperreports.export.xls.remove.empty.space.between.rows" value="true"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="21" splitType="Stretch">
<staticText>
<reportElement uuid="557d6e9d-b389-4710-a66f-f15678ebb003" x="1" y="1" width="119" height="20"/>
<textElement>
<font size="14" isBold="true"/>
</textElement>
<text><![CDATA[Sample Heading]]></text>
</staticText>
</band>
</title>
<pageHeader>
<band height="71" splitType="Stretch">
<staticText>
<reportElement uuid="3d8bfb44-a4ce-409f-a626-4bdba125b0a4" x="0" y="11" width="100" height="20"/>
<textElement verticalAlignment="Middle"/>
<text><![CDATA[Start Date]]></text>
</staticText>
<staticText>
<reportElement uuid="ee347fa8-037a-4fe1-8de2-98867d4903a3" x="0" y="31" width="100" height="20"/>
<textElement verticalAlignment="Middle"/>
<text><![CDATA[Start Date]]></text>
</staticText>
<staticText>
<reportElement uuid="beaa366e-2976-4b46-86ee-55af14249675" x="0" y="51" width="100" height="20"/>
<textElement verticalAlignment="Middle"/>
<text><![CDATA[Start Date]]></text>
</staticText>
<textField pattern="dd-MMM-yy">
<reportElement uuid="4f4124a7-5071-4ced-ba92-c39c6f6ffc54" x="100" y="11" width="100" height="20"/>
<textElement verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression>
</textField>
<textField pattern="dd-MMM-yy">
<reportElement uuid="9492ff27-6c11-417f-8ae9-43dddfcda405" x="100" y="31" width="100" height="20"/>
<textElement verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression>
</textField>
<textField pattern="dd-MMM-yy">
<reportElement uuid="b8baea82-84c4-42fa-bccd-62abc96eeded" x="100" y="51" width="100" height="20"/>
<textElement verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression>
</textField>
</band>
</pageHeader>
<columnHeader>
<band height="69" splitType="Stretch">
<staticText>
<reportElement uuid="1c5d41a5-a86b-4cd0-bac8-19950c3eb5b3" x="0" y="49" width="100" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="12" isBold="true"/>
</textElement>
<text><![CDATA[Heading]]></text>
</staticText>
<staticText>
<reportElement uuid="6d798309-0e10-4c11-8642-53edd66f8ed0" x="100" y="49" width="100" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="12" isBold="true"/>
</textElement>
<text><![CDATA[Heading]]></text>
</staticText>
<staticText>
<reportElement uuid="7ca5ae53-47e2-46f9-90c6-2d8f5d66dc5e" x="200" y="49" width="100" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="12" isBold="true"/>
</textElement>
<text><![CDATA[Heading]]></text>
</staticText>
<staticText>
<reportElement uuid="bae9670f-10fa-4932-9e1b-00c8e38cd009" x="300" y="49" width="100" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="12" isBold="true"/>
</textElement>
<text><![CDATA[Heading]]></text>
</staticText>
<staticText>
<reportElement uuid="bcf09004-a0ca-479f-9d6d-fe2aab932452" x="400" y="49" width="100" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="12" isBold="true"/>
</textElement>
<text><![CDATA[Heading]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="151" splitType="Stretch">
<staticText>
<reportElement uuid="418012e1-fbc2-4cb9-bf7f-2740061bbfd1" x="1" y="0" width="100" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Data]]></text>
</staticText>
<staticText>
<reportElement uuid="9b6a2c68-6327-4a8a-940f-41f5be8bc7ca" x="100" y="0" width="100" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Data]]></text>
</staticText>
<staticText>
<reportElement uuid="7e7ddc5f-31e7-4b76-bbd7-a6f0a2c11169" x="200" y="0" width="100" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Data]]></text>
</staticText>
<staticText>
<reportElement uuid="5f8c4ae6-d2c0-4ded-9e3e-8f1a69995043" x="300" y="0" width="100" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Data]]></text>
</staticText>
<staticText>
<reportElement uuid="f8f51e3b-5dcc-43f0-9f56-00a1bc703ad1" x="400" y="0" width="100" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Data]]></text>
</staticText>
<staticText>
<reportElement uuid="418012e1-fbc2-4cb9-bf7f-2740061bbfd1" x="0" y="20" width="100" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Data]]></text>
</staticText>
<staticText>
<reportElement uuid="418012e1-fbc2-4cb9-bf7f-2740061bbfd1" x="100" y="20" width="100" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Data]]></text>
</staticText>
<staticText>
<reportElement uuid="418012e1-fbc2-4cb9-bf7f-2740061bbfd1" x="200" y="20" width="100" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Data]]></text>
</staticText>
<staticText>
<reportElement uuid="418012e1-fbc2-4cb9-bf7f-2740061bbfd1" x="300" y="20" width="100" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Data]]></text>
</staticText>
<staticText>
<reportElement uuid="418012e1-fbc2-4cb9-bf7f-2740061bbfd1" x="400" y="20" width="100" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Data]]></text>
</staticText>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
Any help in this matter would be appreciated alot. Thanks a bunch!!
Every single time I had problems with that it was because the fields weren't properly aligned. So make sure the fields that should be vertically aligned have the same x value and have the same widths.
Your first Data field is located at x=1 (the other fields on that column are at x=0). Maybe this alone won't solve all the problems, but I am pretty sure the first Data will start to appear in the Excel output.
I ran into a similar issue with Excel exports. I had text fields in my title and report header bands that did not extend the whole width of the report, and some where the left position was not zero (that was intentional on my part, for design purposes). iReport then merged columns to handle this.
To get my Excel exports to look and behave the way I wanted, I had to make my text fields in my title and report header bands the full width of the report and make sure they were aligned to 0 at the left. You can add padding to text fields to position text within them. Anything that happens prior to your detail band needs to be wider than the output in your detail band.
I tried that before, it is because the layout setting doesnt match. You need to make sure the left starting position of each column a the same, and so as their width. If there are merged cells, the width of it need to be exact number of the total of the merged columns width.
go to Tools -> Options -> Export Tools -> Excel -> tick 2nd and 3rd and last 4 ...
Enjoy