How to hide column in excel report generated by JasperReports? - jasper-reports

I want to hide some columns in the excel report for my future reference.
Please suggest me any idea to hide the column.

Alex K's comment is correct. Here's how to apply it:
Open the Source page for the report to view the XML.
Find the field to hide in Excel.
Add the property to the reportElement as follows:
<reportElement x="0" y="0" width="100" height="15">
<property name="net.sf.jasperreports.export.xls.cell.hidden" value="true"/>
</reportElement>
The reportElement attribute values will differ in the report you create.

Related

How to add a table header to an existing jasper table component?

Is there a way to add a table header to an existing jasper report table?
I have an existing jasper report that contains a table component that does not have a table header. I would like to add a table header now, but cannot find any way to do this without completely recreating the table.
Does anyone know of a way to add a Table Header to an existing jasper table component?
You have 2 options, add it directly in jrxml (xml) or use the IDE
1. Add directly to jrxml (go to source view)
In every jr:column you like to have a header add the jr:tableHeader tag as first element
<jr:column width="100" uuid="accf01ee-c512-4854-ae58-97dee667c054">
<jr:tableHeader style="Table_TH" height="30">
<staticText>
<reportElement x="0" y="0" width="100" height="30" uuid="41f6fe02-194f-483e-ab7b-97a6061e2c27"/>
<text><![CDATA[My header]]></text>
</staticText>
</jr:tableHeader>
....
</jr:column>
2. Use the IDE directly
Double click the table component this make it possibile to edit it, navigate in outline to the header node, for every column you like header create the cell and then you will be able to drag a static or dynamic textfield to it.

Show and hide elements for different exporters [duplicate]

I have a JasperReports jrxml file which has a hyperlink inside a textField element.
I do not want to show this hyperlink in anything other than the HTML view because the link does not work in excel, PDF, word, etc. and does not make sense to show.
I have read the faq with the properties but it just confused me because it does not talk about hiding a textField at all, just "bands" for headers and footers.
Here is the text field I want to hide when not HTML:
<textField hyperlinkType="ReportExecution">
<reportElement style="Report_Param_Value_Link" mode="Opaque" x="400" y="0" width="161" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[Boolean.TRUE.equals($P{LAST_WEEK}) ? "View WTD" : "View last week"]]></textFieldExpression>
<hyperlinkParameter name="noMenu">
<hyperlinkParameterExpression><![CDATA["true"]]></hyperlinkParameterExpression>
</hyperlinkParameter>
<hyperlinkParameter name="reportUnit">
<hyperlinkParameterExpression><![CDATA["repo:/Reports/Operations/Business_Support/Subreports/Business_Support_Performance_Dashboard"]]></hyperlinkParameterExpression>
</hyperlinkParameter>
<hyperlinkParameter name="LAST_WEEK">
<hyperlinkParameterExpression><![CDATA[Boolean.valueOf(!Boolean.TRUE.equals($P{LAST_WEEK})).toString()]]></hyperlinkParameterExpression>
</hyperlinkParameter>
</textField>
Use an Element Key Filter.
The quote from JR Ultimate Guide:
This built-in filter implementations excludes from export elements that match a given element key.
Element keys are set at report design time and are propagated into generated reports.
Each element in a filled report has the same key as the element from the report template that generated it.
To trigger an element key filter, the report designer needs to define one or more report properties that start with <exporter_property_prefix>.exclude.key. Each such property matches a single element key which is to be excluded by the filter. The element key is given by the property value, or if no value is set for the property, by the property suffix.
The following example shows how to specify element keys which are to be excluded from specific export outputs:
<jasperReport ...>
<!-- exclude elements with keys Image1 and Text4 from HTML export-->
<property name="net.sf.jasperreports.export.html.exclude.key.Image1"/>
<property name="net.sf.jasperreports.export.html.exclude.key.Text4"/>
<!-- exclude elements with keys Image5 from PDF export -->
<property name="net.sf.jasperreports.export.pdf.exclude.key.the.image" value=”Image5”/>
...
</jasperReport>
In your case you should add key for text field with hyperlink (for example, textFieldWithHL) and then add one property for each format (pdf, docx, xls, csv, xml, txt, odt) you want to exclude from printing this hyperlink:
<property name="net.sf.jasperreports.export.pdf.exclude.key.textFieldWithHL"/>
<property name="net.sf.jasperreports.export.docx.exclude.key.textFieldWithHL"/>
<property name="net.sf.jasperreports.export.xls.exclude.key.textFieldWithHL"/>
<property name="net.sf.jasperreports.export.csv.exclude.key.textFieldWithHL"/>
<property name="net.sf.jasperreports.export.xml.exclude.key.textFieldWithHL"/>
The expressions from your post:
net.sf.jasperreports.export.{format}.exclude.origin.{suffix}.{arbitrary_name}
net.sf.jasperreports.export.{format}.exclude.origin.keep.first.{suffix}.{arbitrary_name}
allow to exclude the whole bands (also group bands). This filters work with JROrigin objects.
For example, consider a report with a logo that must be included as SVG for PDF output or PNG for HTML output. The JRXML file contains:
<image scaleImage="RetainShape" onErrorType="Blank">
<reportElement key="IMAGE_LOGO_PNG" x="1" y="0" width="100" height="60" uuid="a896cade-f6fc-4d8f-b762-29b950309257"/>
<imageExpression><![CDATA[Transcoder.asPNG($V{V_LOGO_FILE} + ".svg")]]></imageExpression>
</image>
<image scaleImage="RetainShape" onErrorType="Blank">
<reportElement key="IMAGE_LOGO_SVG" x="1" y="0" width="100" height="60" uuid="a896cade-f6fc-4d8f-b762-29b950309257"/>
<imageExpression><![CDATA[Transcoder.asSVG($V{V_LOGO_FILE} + ".svg")]]></imageExpression>
</image>
To exclude the SVG from HTML and the PNG from PDF, add the following properties immediately after the <jasperReport...> root element in the JRXML file:
<property name="net.sf.jasperreports.export.html.exclude.key.IMAGE_LOGO_SVG"/>
<property name="net.sf.jasperreports.export.pdf.exclude.key.IMAGE_LOGO_PNG"/>
Looking at your source, it may be possible to create an ExporterFilter that suppresses hyperlinks, and then you have to add that filter to the export process for everything except HTML. However, I don't see why you don't want to show the hyperlink in the other formats. For many years PDF, Word, Excel, etc. will all interpret a hyperlink correctly, and in fact respond to a mouse click on the link just like a browser. That's probably why the process is going to be painful: you are reversing what for most people is expected behavior.

Unable to add extra content into exported word doument from jasper report

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"/>

Make lines with iReport?

How can I do this with iReport (using iReport v4.0)?
Here is jrxml file
it depend on the size of Sub-report, check the sub-repot preview, if you want to increase the size of sub-rport in main report , for this you have to increase the size of sub-reportas where it is separately created.
You could try using background band for those lines.
Maybe inside your parent report
When you create a sub-report you can delete; Page Header, Column Header and Page Footer bands on your main report. After then, you can drag and drop sub-report icon on Summary part of your main report. You will probably use ColumnHeader and Detail bands on your Sub-Report. (It depends on your design. If you use subreports recursively, you can use again summary band.) Later,you will select Remove Report Margins on your subreport. To get expected result; your subreport icon Width on main report should equal your subreport page width.
Adding borders worked great for me. Expand your text element to cell size, right click -> Padding and Borders and add them all around. It's easier than having to handle draw lines. Less elements and faster editing.
You can add lines via the iReport Designer gui interface using the Palette (go to Window > Palette, then click Line, then drag it over to the Designer).
You can also add lines by modifying the jrxml code directly. I haven't found guidance in the documentation on this. But this answer to another question shows how to create a vertical line:
<line>
<reportElement x="0" y="0" width="1" height="30"/>
</line>
And it also shows how to create a horizontal line:
<line>
<reportElement x="0" y="0" width="30" height="1"/>
</line>
Also, the JRXML Sources and Jasper Files section of the documentation has some more involved code such as the following, which uses a direction parameter with value BottomUp (there are also references to TopDown in the community site or here):
<line direction="BottomUp">
<reportElement key="line" x="1" y="4" width="554" height="1"/>
</line>
And this, which uses positionType parameter of FixRelativeToBottom:
<line>
<reportElement positionType="FixRelativeToBottom" x="0" y="51" width="555"
height="1"/>
</line>

How to hide textField for specified exporter. For example for not HTML

I have a JasperReports jrxml file which has a hyperlink inside a textField element.
I do not want to show this hyperlink in anything other than the HTML view because the link does not work in excel, PDF, word, etc. and does not make sense to show.
I have read the faq with the properties but it just confused me because it does not talk about hiding a textField at all, just "bands" for headers and footers.
Here is the text field I want to hide when not HTML:
<textField hyperlinkType="ReportExecution">
<reportElement style="Report_Param_Value_Link" mode="Opaque" x="400" y="0" width="161" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[Boolean.TRUE.equals($P{LAST_WEEK}) ? "View WTD" : "View last week"]]></textFieldExpression>
<hyperlinkParameter name="noMenu">
<hyperlinkParameterExpression><![CDATA["true"]]></hyperlinkParameterExpression>
</hyperlinkParameter>
<hyperlinkParameter name="reportUnit">
<hyperlinkParameterExpression><![CDATA["repo:/Reports/Operations/Business_Support/Subreports/Business_Support_Performance_Dashboard"]]></hyperlinkParameterExpression>
</hyperlinkParameter>
<hyperlinkParameter name="LAST_WEEK">
<hyperlinkParameterExpression><![CDATA[Boolean.valueOf(!Boolean.TRUE.equals($P{LAST_WEEK})).toString()]]></hyperlinkParameterExpression>
</hyperlinkParameter>
</textField>
Use an Element Key Filter.
The quote from JR Ultimate Guide:
This built-in filter implementations excludes from export elements that match a given element key.
Element keys are set at report design time and are propagated into generated reports.
Each element in a filled report has the same key as the element from the report template that generated it.
To trigger an element key filter, the report designer needs to define one or more report properties that start with <exporter_property_prefix>.exclude.key. Each such property matches a single element key which is to be excluded by the filter. The element key is given by the property value, or if no value is set for the property, by the property suffix.
The following example shows how to specify element keys which are to be excluded from specific export outputs:
<jasperReport ...>
<!-- exclude elements with keys Image1 and Text4 from HTML export-->
<property name="net.sf.jasperreports.export.html.exclude.key.Image1"/>
<property name="net.sf.jasperreports.export.html.exclude.key.Text4"/>
<!-- exclude elements with keys Image5 from PDF export -->
<property name="net.sf.jasperreports.export.pdf.exclude.key.the.image" value=”Image5”/>
...
</jasperReport>
In your case you should add key for text field with hyperlink (for example, textFieldWithHL) and then add one property for each format (pdf, docx, xls, csv, xml, txt, odt) you want to exclude from printing this hyperlink:
<property name="net.sf.jasperreports.export.pdf.exclude.key.textFieldWithHL"/>
<property name="net.sf.jasperreports.export.docx.exclude.key.textFieldWithHL"/>
<property name="net.sf.jasperreports.export.xls.exclude.key.textFieldWithHL"/>
<property name="net.sf.jasperreports.export.csv.exclude.key.textFieldWithHL"/>
<property name="net.sf.jasperreports.export.xml.exclude.key.textFieldWithHL"/>
The expressions from your post:
net.sf.jasperreports.export.{format}.exclude.origin.{suffix}.{arbitrary_name}
net.sf.jasperreports.export.{format}.exclude.origin.keep.first.{suffix}.{arbitrary_name}
allow to exclude the whole bands (also group bands). This filters work with JROrigin objects.
For example, consider a report with a logo that must be included as SVG for PDF output or PNG for HTML output. The JRXML file contains:
<image scaleImage="RetainShape" onErrorType="Blank">
<reportElement key="IMAGE_LOGO_PNG" x="1" y="0" width="100" height="60" uuid="a896cade-f6fc-4d8f-b762-29b950309257"/>
<imageExpression><![CDATA[Transcoder.asPNG($V{V_LOGO_FILE} + ".svg")]]></imageExpression>
</image>
<image scaleImage="RetainShape" onErrorType="Blank">
<reportElement key="IMAGE_LOGO_SVG" x="1" y="0" width="100" height="60" uuid="a896cade-f6fc-4d8f-b762-29b950309257"/>
<imageExpression><![CDATA[Transcoder.asSVG($V{V_LOGO_FILE} + ".svg")]]></imageExpression>
</image>
To exclude the SVG from HTML and the PNG from PDF, add the following properties immediately after the <jasperReport...> root element in the JRXML file:
<property name="net.sf.jasperreports.export.html.exclude.key.IMAGE_LOGO_SVG"/>
<property name="net.sf.jasperreports.export.pdf.exclude.key.IMAGE_LOGO_PNG"/>
Looking at your source, it may be possible to create an ExporterFilter that suppresses hyperlinks, and then you have to add that filter to the export process for everything except HTML. However, I don't see why you don't want to show the hyperlink in the other formats. For many years PDF, Word, Excel, etc. will all interpret a hyperlink correctly, and in fact respond to a mouse click on the link just like a browser. That's probably why the process is going to be painful: you are reversing what for most people is expected behavior.