This question already has answers here:
How can I have long text in a single line excel cell?
(2 answers)
Display Full Text in Excel without truncation
(2 answers)
JasperReport - wrap text to show long text in textfield
(3 answers)
How to stretch textfield in a JasperReport as per dynamic content?
(8 answers)
Closed 2 years ago.
I would like to force a break in textfield for very long text. I don't care if there is a space or not in the text. I just want the text to appear in the next line if it is too long for the textfield width.
I have tried this:
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement key="textField-2" positionType="Float" stretchType="RelativeToTallestObject" x="409" y="170" width="146" height="28">
<property name="net.sf.jasperreports.text.save.line.breaks" value="true"/>
</reportElement>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textElement>
<font fontName="Courier New" size="8"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{customerReference}]]></textFieldExpression>
</textField>
But it is not working. I just cuts off the text after the first hyphen and the rest of the text is not displayed.
An example text is:
SIN684473 - 403904156/OO0D628902B SIN684473 - 403904156/OO0D628902B
Please help. Thanks.
EDIT 1: Thanks to Alex K, it is now working in PDF. But now in the Excel file, the field of customerReference is empty. But it is not empty in PDF.
Please help. Thanks.
Related
I have a problem with correctly setting paddings in JasperReports tables.
I'm using styles to uniformly configure text boxes of the same purpose, eg. for displaying currency. However, the paddings behave differently in text fields in table body and table footer. Inside the table, the top and bottom padding works correcly, however, left and right not. The 2 pixels are ignored, so I'd have to use 4 to get 2.
In table footer, paddings work normally, which makes numbers misaligned. But the whole footer cell looks to be shifted.
This is my JRXML fragment:
<jr:tableFooter style="Table_TH" height="16" rowSpan="1">
<textField>
<reportElement style="Custom_Currency" x="0" y="0" width="105" height="16" isRemoveLineWhenBlank="true"/>
<textFieldExpression><![CDATA[$P{taxTotal}]]></textFieldExpression>
</textField>
</jr:tableFooter>
<jr:detailCell style="Table_TD" height="16">
<textField>
<reportElement style="Custom_Currency" x="0" y="0" width="105" height="16" />
<textFieldExpression><![CDATA[$F{tax}]]></textFieldExpression>
</textField>
</jr:detailCell>
<style name="Custom_Text" mode="Opaque" backcolor="#EBEBEB" pattern="" isBlankWhenNull="true" fontSize="8">
<box topPadding="2" leftPadding="2" bottomPadding="2" rightPadding="2">
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
</style>
<style name="Custom_Currency" style="DF_Text" hTextAlign="Right" pattern="#,##0.00">
<box topPadding="2" leftPadding="4" bottomPadding="2" rightPadding="4"/>
</style>
and this is how it looks in action:
How should I declare paddings so that they work consistently in my whole report?
Im making a report using JasperReports and iReport, and since im not using a table, what i'm doing now to give it some sort of table like border, is giving the left and right border of each textfield a dotted style.
But, i won't always have the same data in each box, and this is causing the borders to be of different height.
I also would like for the borders to meet each other, but no matter what i change or move, there's always a space in between each box.
But for now, the most important thing is for each box to have the same height.
This is a picture of my report:
This is what each box looks like, they're all similar so i just pasted one the xml of one box:
<textField isStretchWithOverflow="true" pattern="" isBlankWhenNull="true">
<reportElement key="textField-1" mode="Transparent" x="7" y="0" width="177" height="0" isRemoveLineWhenBlank="true" forecolor="#000000" backcolor="#FFFFFF">
<printWhenExpression><![CDATA[$F{RESULTMICRO1}!=null]]></printWhenExpression>
</reportElement>
<box leftPadding="1">
<pen lineWidth="0.0"/>
<topPen lineWidth="0.5" lineStyle="Dashed"/>
<leftPen lineWidth="0.5" lineStyle="Dashed"/>
<bottomPen lineWidth="0.5" lineStyle="Dashed"/>
<rightPen lineWidth="0.5" lineStyle="Dashed"/>
</box>
<textElement textAlignment="Left" verticalAlignment="Top" rotation="None">
<font fontName="Courier New" size="9" isBold="false" isItalic="true" isUnderline="false" isStrikeThrough="false" pdfFontName="Courier-Bold" pdfEncoding="Cp1252" isPdfEmbedded="true"/>
<paragraph lineSpacing="Single"/>
</textElement>
<textFieldExpression><![CDATA[$F{RESULTMICRO1}]]></textFieldExpression>
If anyone could help me, i'd appreciate it.
I want to hide a text field using jasper report so when i will view it in html i wont see its content, but the problem is that it has to be there (proggram JAWS has to read it) so i can't use "printWhenExpression". I tried to use width properties to hide it but so far i have no effect.
<textField>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textFieldExpression><![CDATA[$V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
If I understood correctly, you need to keep the shape of the box as if the content was here, but you want the content to disappear.
It's true that printWhenExpression will make the whole item disappear.
You can either :
Use a parent item such as a frame to be around the textField, so printWhenExpression is true on the text fields, then the frame will still be here to keep its place.
<frame>
<reportElement x="0" y="0" width="200" height="200" uuid="25b397bf-e718-43ab-8641-4f7c7932253f"/>
<textField>
<reportElement x="0" y="0" width="100" height="30" uuid="4e8ea258-88f0-4220-a350-448da63390d1">
<printWhenExpression><![CDATA[the_condition]]></printWhenExpression>
</reportElement>
<textFieldExpression><![CDATA[$V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
</frame>
Use a java condition in your text field. If the condition is false, the text will disappear but the text field frame will still be displayed.
<textField>
<reportElement x="0" y="0" width="100" height="30" uuid="4e8ea258-88f0-4220-a350-448da63390d1">
<printWhenExpression><![CDATA[the_condition]]></printWhenExpression>
</reportElement>
<textFieldExpression><![CDATA[my_condition ? $V{PAGE_NUMBER} : ""]]></textFieldExpression>
</textField>
Is it possible to remove the extra padding in text fields/static text fields? Here's an example:
EDIT: I don't mean the width of the text field, I'm referring to the height.
I have the pixel size of the text field set to the lowest possible number without the text disappearing.
The padding on the field is set to 0.
I'm finding that I'm wasting a ton of extra space with this padding. I'm not sure I'm able to fit the required information in a one page report with the font sizes I'm required to use.
minus is also working in padding. Below code did save me. Please note in below code i am using minus thirteen. As you incerese minus number, padding becomes smaller and smaller.
<box topPadding="-13" leftPadding="3" bottomPadding="-13" rightPadding="3">
<pen lineWidth="1.0"/>
<topPen lineWidth="1.0" lineColor="#666666"/>
<leftPen lineWidth="1.0" lineStyle="Dotted" lineColor="#FFFFFF"/>
<bottomPen lineWidth="1.0" lineColor="#666666"/>
<rightPen lineWidth="1.0" lineColor="#666666"/>
</box>
Actually, I found a way to do it, although kind of hacky.
It's the "box" element that's providing the padding (for borders).
In order to remove the padding, set the box padding to -1 like so:
<staticText>
<reportElement x="10" y="271" width="160" height="15" uuid="325acf4c-c003-4d50-aa1e-a3ae1c8f0dff">
<property name="local_mesure_unitheight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</reportElement>
<box padding="-1"/>
<textElement>
<font size="12" isBold="true"/>
</textElement>
<text><![CDATA[SPECIAL INSTRUCTIONS]]></text>
</staticText>
I have a table in a jasper report, and I need the contents of certain cells in that table to be vertically aligned. I'm attempting to edit the report with iReport.
In iReport I can go into the properties of a cell and see that the vertical align is set to "Middle". Additionally, when I look at the XML directly (see below), I can see that the textElement tag has a verticalAlignment="Middle" attribute.
So near as I can tell the text should be vertically aligned within its little box, and yet it will not align properly.
I'm hoping that someone experienced with vertically aligning things in jasper reports can point out what I'm doing wrong. Thanks much.
<textField
isStretchWithOverflow="false"
isBlankWhenNull="true"
evaluationTime="Now"
hyperlinkType="None"
hyperlinkTarget="Self" >
<reportElement
x="227"
y="0"
width="31"
height="14"
key="textField-4"/>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineColor="#000000"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Times New Roman" pdfFontName="Times-Roman" size="8"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{someVariableName}]]></textFieldExpression>
</textField>
So, to be clear, what I have in my report is something like this:
|--------|
| text |
| |
| |
|--------|
And what I want is something like this:
|--------|
| |
| text |
| |
|--------|
Here's how I fixed this problem (iReport 3.7.6):
In Designer tab:
Right Click on the Static Text Box
Select "Padding and Borders"
In the pop up box, Increase the "Top" or "Bottom" value by, for example, 5, and click OK to see the result of this change.
As you can see, this will allow you to position your Static Text exactly how you want.
If you can only make the change in the XML, this is how the change showed up in XML:
<box topPadding="4"/>
Example w/ the Static Text code block:
<staticText>
<reportElement positionType="Float" mode="Opaque" x="14" y="27" width="118" height="14" forecolor="#FFFFFF" backcolor="#909090"/>
<box topPadding="4"/>
<textElement textAlignment="Center" verticalAlignment="Middle" rotation="None" lineSpacing="Single" markup="none">
<font fontName="Arial" size="7" isBold="true" isUnderline="false" isStrikeThrough="false" isPdfEmbedded="false"/>
</textElement>
<text><![CDATA[SAMPLE TEXT SAMPLE TEXT]]></text>
</staticText>
you can 1) check if positionType="FixRelativeToTop" 2) create a style with alingn = middle and apply it to your item - maybe this can help.