How to export an image that is a blob in database from a jasper reports to excel?

后端 未结 1 507
无人及你
无人及你 2020-12-11 09:08

In ireportDesigner 5.6.0, I am adding an image from database. When I add that image,in xml it is shown as java.lang.Object and I have changed it to java.a

相关标签:
1条回答
  • 2020-12-11 09:54

    With additional info that you added this is what I would do:

    1. The correct field class should be java.sql.Blob (corrispond to the database mapping)

      <field name="companyLogo" class="java.sql.Blob">
         <fieldDescription><![CDATA[]]></fieldDescription>
      </field>
      
    2. The image expression should be (On the Blob we call the getBinaryStream() that gives us a java.io.InputStream)

       <image>
          <reportElement x="0" y="0" width="107" height="79" uuid="fba6c6a9-42a2-4ffb-9d80-f0721728a7b6"/>
          <imageExpression class="java.io.InputStream"><![CDATA[$F{companyLogo}.getBinaryStream()]]></imageExpression>
       </image>
      

    To improve code some it would be great to check that $F{companyLogo}!=null,

    a small note... why not pass it as parameter, hence load it in your java and pass it as a java.io.InputStream or java.io.Image... this way maybe also your jasper gets cleaner...

    0 讨论(0)
提交回复
热议问题