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

后端 未结 2 703
心在旅途
心在旅途 2020-11-28 14:50

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 vie

相关标签:
2条回答
  • 2020-11-28 14:57

    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.

    0 讨论(0)
  • 2020-11-28 15:21

    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"/>
    
    0 讨论(0)
提交回复
热议问题