Excel not well formated in JasperReports - excel

When i export my report to Excel, my cells don't display the whole text if there is more than one row to be displayed in it; it just cuts a part of it and i need to expand the row manually to see the all the data in it
I use the following formatting:
<band height="21">
<staticText>
<reportElement style="pageHeader" mode="Opaque" x="0" y="6" width="88" height="15"/>
<textElement textAlignment="Left">
<font fontName="Cambria" size="10"/>
</textElement>
<text><![CDATA[First Name]]></text>
</staticText>
</band>
<band height="30" splitType="Prevent">
<textField isStretchWithOverflow="true">
<reportElement positionType="Float" stretchType="RelativeToTallestObject" x="0" y="0" width="88" height="25"/>
<textElement textAlignment="Left">
<font fontName="Cambria" size="10"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{firstName}]]></textFieldExpression>
</textField>
</band>
Is there a xls property i should set?

I solved this problem setting line spacing to double at text field properties menu.
Dosn't look different but shows full text.

Related

Pagination adds an extra blank page at the end

Given the footer of my report :
<pageFooter>
<band height="51" splitType="Stretch">
<textField isStretchWithOverflow="true">
<reportElement positionType = "Float" x="485" y="1" width="55" height="50" uuid="7786fb05-689a-4b6a-915a-a7bcf3abad95"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Calibri" size="10" />
<paragraph lineSpacingSize="0"/>
</textElement>
<textFieldExpression><![CDATA[" - "]]> + $V{PAGE_NUMBER} + <![CDATA[" - "]]></textFieldExpression>
</textField>
</band>
</pageFooter>
My report adds an extra blank page without page number at the end of the report unlike the previous report pages each of which has a page number. When I have tried to remove the pagination and use a staticText component as my footer, the extra blank page is gone.
How could one solve this problem please?

JasperReport: sum fields disappear after xls sorting

I have such xls file generated by jasper:
sum fields has following jrxml properties:
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement positionType="Float" stretchType="RelativeToTallestObject" x="1050" y="13" width="90" height="11" isPrintWhenDetailOverflows="true" uuid="a41d8696-c8a2-43bc-a41c-1bfe5499d3d4"/>
<textElement textAlignment="Right">
<font size="8" isBold="true"/>
<paragraph lineSpacing="1_1_2"/>
</textElement>
<textFieldExpression>##my_experssion##</textFieldExpression>
</textField>
After I sort by column I sum fields disappear
Is there any simple way to fix this?

How to group properly excel data source with rowspan?

From my understanding, <groupExpression> tag will be the one that decides whether a new group will be created or not, if there's a change to the element inside <groupExpression>, a new group will be created.
I want my report to look similar to my Excel data source (refer below) hence I want to group the ID and Name in the Excel file. In my jasperReport.jrxml (refer below), my <groupExpression> for Group1 is the ID column of my Excel File. But when I preview the report (refer below), the ID and Name column is not grouped, instead, there's a null string.
How to properly group them and eliminate the null string?
Excel datasource:
jasperReport.jrxml
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.2.0.final using JasperReports Library version 6.2.0 -->
<!-- 2016-01-26T15:33:41 -->
<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="FirstJasperReport" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="8b8832df-588e-4202-826e-a6b3efcbd22b">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="ExcelDataBase"/>
<queryString>
<![CDATA[]]>
</queryString>
<field name="ID" class="java.lang.Integer"/>
<field name="Name" class="java.lang.String"/>
<field name="Title" class="java.lang.String"/>
<field name="Balance" class="java.lang.Integer"/>
<variable name="Balance1" class="java.lang.Integer" resetType="Group" resetGroup="Group1" calculation="Count">
<variableExpression><![CDATA[$F{Balance}]]></variableExpression>
</variable>
<variable name="Balance2" class="java.lang.Integer" resetType="Group" resetGroup="Group1" calculation="Sum">
<variableExpression><![CDATA[$F{Balance}]]></variableExpression>
</variable>
<group name="Group1">
<groupExpression><![CDATA[$F{ID}]]></groupExpression>
<groupHeader>
<band height="30">
<rectangle>
<reportElement x="0" y="0" width="400" height="30" backcolor="#DEFCF2" uuid="de6c2f8d-afa6-45b4-b40e-574f2e07057e"/>
</rectangle>
<textField>
<reportElement x="0" y="0" width="100" height="30" uuid="c028645d-9b29-42d3-b91e-d47f15a5b44a"/>
<textFieldExpression><![CDATA[$F{ID}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="100" y="0" width="100" height="30" uuid="85d2844f-ef91-47a1-9223-c6943a25fe4d"/>
<textFieldExpression><![CDATA[$F{Name}]]></textFieldExpression>
</textField>
</band>
</groupHeader>
......
Preview result:
How to make title1 and title2 appear under the group test1, without the null string (similar to the Excel source file)?
The problem is that the excel datasource is passing $F{ID}==null for second record. This generates the null group (as you can see also the name is null).
The easiest way to fix it is to not use rowspan in excel (include all data in the excel sheet).
If this is not possible you need to save the first $F{ID} value and return this if $F{ID}==null
Example
<variable name="First_ID" class="java.lang.Integer" resetType="Group" resetGroup="Group1" calculation="First">
<variableExpression><![CDATA[$F{ID}]]></variableExpression>
</variable>
In group return variable $V{First_ID} if $F{ID}==null
<group name="Group1">
<groupExpression><![CDATA[$F{ID}==null?$V{First_ID}:$F{ID}]]></groupExpression>
... your groupHeader ....
</group>

how to order an svg visibility animation to toggle do one image after another

I want to make some images included in an svg file toggle on and off in order. To do this I need to know how to set my begin and dur attributes on the animate element.
Assuming I have images like the following
<image visibility="visible" xlink:href="image1.gif" x="0" y="0" height="100%" width="100%">
<animate attributeName="visibility" begin="0s"
from="visible" to="hidden" dur="5s" repeatCount="indefinite" />
</image>
<image visibility="hidden" xlink:href="image2.gif" x="0" y="0" height="100%" width="100%">
<animate attributeName="visibility" begin="5s"
from="hidden" to="visible" dur="4s" repeatCount="indefinite" />
</image>
How do I get them to toggle their visibility in order, so that the first image is visible at first for 4 seconds, it turns invisible the next image is visible for exactly 4 seconds, it turns invisible and the previous image is now visible for the next 4 seconds.
I would really prefer to do this with the declarative animation style.
Ok I figured out how to do it from an example in the book SVG Unleashed http://my.safaribooksonline.com/book/photo-and-graphic-manipulation/0672324296
<image visibility="visible" xlink:href="image1.gif" x="0" y="0" height="100%" width="100%">
<animate id="img1ani" attributeName="visibility" begin="1s; img2ani.end+1s"
from="visible" to="hidden" dur="5s" fill="freeze" />
</image>
<image id="img2" visibility="hidden" xlink:href="image2.gif" x="0" y="0" height="100%" width="100%">
<animate id="img2ani" attributeName="visibility" begin="img1ani.end+1s"
from="hidden" to="visible" dur="5s"/>
</image>
just in case anyone else has the same problem,img1ani begins after 1 second or 1 second after image2ani ends while img2ani begins 1 second after img1ani ends.
So in this way it toggles between the two images.

SVG scaled within SVG at specific location(s)

I'm new to complex SVG and working on something and need help. I have a couple of SVG files that are already properly formatted with content.. lines, rectangles, text, etc. They are drawn with simple X=, Y=, X1=, Y1= and based on just whole numbers. The original SVG was designed for printing and the x/y positions were set based on printing at 300dpi.
So this exists with a couple SVG coming from other origins and I'm trying to merge into a new single SVG document. So, one of these elements, I need to put at position (x,y) based on either inches or centimeters (from what I've read so far), but I also need them to respect a specific size of... say 2 in tall, 3.4in wide.
Since the original SVG was based on just whole numbers and no orientation to "inches", what can I do.. or, how can it self-scale.
Without proper SVG syntax, here's basically some of the details.
SVG1 has an overall x/y rectangle area of 0,0 to 476,100
SVG2 has an overall x/y rectangle area of 0,0 to 273,24
The new SVG needs to be 4" by 6"
Ex: at position 1/4" down, 1" across from the top, I need to insert SVG1, and even though it is 476x100, it needs to be scaled into an area about 1/2" tall x 3" wide.
Similarly,
at position 2.8" down, 1.75" across, I need to insert SVG2, and its size needs to be about 2" tall, and 2.5" wide as a maximum area.
Scaled yes, but not to be skewed, they need to keep their original proportions and not clipped. If I can get the basic understanding, I can tweak the final dimensions, just don't know how to get the infrastructure of this working.
Thanks.
I finally got it after much playing around, just in case anyone is interested and relatively new with SVG as I am. As in the question, I had some pre-generated SVG output files that have their X,Y Height,Width settings all based on numeric value, with no context to inch, centimeter, etc. but my requirement was to fit into a given X inch by Y inch range.
So, I found out about "defs" tag, which is like declaring a variable that can later be used as a "put that thing HERE" within the later SVG body. At the TOP of the SVG, I was able to give the dimensions I needed. Then, by using the "g" tag for grouping, I am able to numerically position something to a given x,y position. Then, within that, I did another "g" to apply a scaling of the "variable" as declared in the "defs" section (as a "g" element can not have two "transform" tags within it).
What I came up with was something like below, and hope the detailed comments can help others in their research dealing with SVG.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Explicitly define the SVG window area as 4 inches by 6 inches -->
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="4in" height="6in" >
<!-- Add some styles, fonts etc for line drawing, labels and data -->
<style type="text/css" >
<![CDATA[
line.Black
{ stroke:RGB(0,0,0);
stroke-width:2;
}
text.Hdr
{
font-family: Arial;
font-size:x-small;
stroke: #000000;
stroke-width:.4;
}
text.Data
{
font-family: Courier New;
font-size:normal;
stroke: #000000;
stroke-width:.5;
}
]]>
</style>
<!-- all these "defs" are zero-based position for their own content
and will be speicifcally placed where needed via "g" tags.
The simple "id" name will be used as an "insert <something> here" -->
<defs>
<!-- Below will come from actual data from system
The "ID" is what becomes the "variable" that is later
used later in the SVG as the "put me here" -->
<g id="DataOneElement" >
<text class="Data">SOME TEXT DATA</text>
</g>
<!-- This partial linear barcode generated somewhere else
Notice these are just integer positions, and nothing
to do with specific "inches" measurements. Also, they
start at position 0,0 and go however large they need.
When applied with the "g" positioning, thats where it
starts, then gets scaled from there if needed bigger/smaller -->
<g id="DataPartialBarCode" >
<rect x="0" y="0" width="1" height="50" />
<rect x="4" y="0" width="1" height="50" />
<rect x="6" y="0" width="3" height="50" />
<rect x="10" y="0" width="3" height="50" />
<rect x="14" y="0" width="1" height="50" />
<rect x="16" y="0" width="3" height="50" />
<rect x="20" y="0" width="3" height="50" />
<rect x="24" y="0" width="1" height="50" />
<rect x="26" y="0" width="1" height="50" />
<rect x="30" y="0" width="1" height="50" />
<rect x="32" y="0" width="1" height="50" />
<rect x="34" y="0" width="1" height="50" />
<rect x="38" y="0" width="3" height="50" />
</g>
<!-- Actual data generated from AMS to populate these too.
Notice here too, the entire address starts as position 0,0 -->
<g id="SampleAddress" >
<text class="Data" x="0" y="0">Some Person's Name</text>
<text class="Data" x="0" y="17">First Address Line</text>
<text class="Data" x="0" y="30">Another Address</text>
<text class="Data" x="0" y="43">3rd Address line</text>
<text class="Data" x="0" y="56">And Testing for longer address content</text>
</g>
<!-- another bar code that will generated -->
<g id="AnotherBarCode" >
<rect x="0" y="0" width="1" height="70" />
<rect x="4" y="0" width="1" height="70" />
<rect x="6" y="0" width="3" height="70" />
<rect x="10" y="0" width="3" height="70" />
<rect x="14" y="0" width="1" height="70" />
<rect x="16" y="0" width="3" height="70" />
<rect x="20" y="0" width="1" height="70" />
<rect x="24" y="0" width="1" height="70" />
<rect x="26" y="0" width="1" height="70" />
<rect x="28" y="0" width="3" height="70" />
<rect x="32" y="0" width="1" height="70" />
<rect x="36" y="0" width="1" height="70" />
<rect x="38" y="0" width="3" height="70" />
<rect x="42" y="0" width="3" height="70" />
<rect x="46" y="0" width="1" height="70" />
</g>
</defs>
<!-- Now, starting the drawing of the SVG...
Border around entire box drawing area
Notice these are in specific INCH dimensions... -->
<line class="Black" x1="0in" y1="0in" x2="4in" y2="0in" />
<line class="Black" x1="0in" y1="0in" x2="0in" y2="6in" />
<line class="Black" x1="4in" y1="0in" x2="4in" y2="6in" />
<line class="Black" x1="0in" y1="6in" x2="4in" y2="6in" />
<!-- Translate is Across then Down from the top/left corner of SVG -->
<!-- Translate is NOT based on inch, cm, or other measurements
so you may have to tweak these numbers -->
<g transform="translate( 100 20 ) ">
<!-- Now, take whatever we are providing and scale it within the area.
In this case, scale the ENTIRE "g" object to 1.5 its original size -->
<g transform="scale(1.75)">
<!-- This is where the "defs" variable declaration comes
in, as looking at the "g" tag by the ID name -->
<use xlink:href="#DataOneElement" />
</g>
</g>
<!-- and now the partial barcode "defs" variable -->
<g transform="translate( 20 23 ) ">
<!-- In this case, scale the width by 115% and the height by 95% -->
<g transform="scale( 1.15 .95 )">
<use xlink:href="#DataPartialBarCode" />
</g>
</g>
<!-- Any other specific lines within the area -->
<line class="Black" x1="0in" y1=".8in" x2="4in" y2=".8in" />
<!-- Now, just insert the "defs" from above at a scale that will still be readable.
Cool thing, the entire address is considered a single element here. -->
<g transform="translate(20 97)">
<g transform="scale(.7)">
<use xlink:href="#SampleAddress" />
</g>
</g>
<!-- We can even show the address AGAIN, scaled differently elsewhere. -->
<g transform="translate(2 250)">
<g transform="scale(1.3)">
<use xlink:href="#SampleAddress" />
</g>
</g>
<!-- Another line and then barcode-->
<line class="Black" x1="0in" y1="1.55in" x2="4in" y2="1.55in" />
<g transform="translate( 175 175 ) ">
<!-- Scale this barcode 100% wide, but only 70% height -->
<g transform="scale(1 .7)">
<use xlink:href="#AnotherBarCode" />
</g>
</g>
</svg>

Resources