简体   繁体   中英

how can i export to Standard excel file from jasper with the image and cell border and the excel file look likes normal excel file?

I am using jasper report to export my excel report in my liferay custom portlet JSP Page.

now what happen is when i set IS_IGNORE_GRAPHICS property false then its showing image in excel report.but then the column of excel report not showing any border..and if i set it to true then its not showing image and then every column comes with border..now what i want is both as image on the excel report as well as the cell border of the excel report.

following is my jrxml file

<?xml version="1.0" encoding="UTF-8"?>
<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="RestaurantReport" language="groovy" pageWidth="595" pageHeight="520" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isFloatColumnFooter="true">
    <property name="ireport.zoom" value="1.1000000000000032"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="0"/>
    <property name="net.sf.jasperreports.export.xls.ignore.graphics" value="false"/>
    <style name="table">
        <box>
            <pen lineWidth="1.0" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_TH" mode="Opaque" backcolor="#F0F8FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_CH" mode="Opaque" backcolor="#BFE1FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_TD" mode="Opaque" backcolor="#FFFFFF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <subDataset name="Table Dataset 1"/>
    <field name="advertisename" class="java.lang.String"/>
    <field name="camp_name" class="java.lang.String"/>
    <field name="ad_location" class="java.lang.String"/>
    <field name="clicked" class="java.lang.Integer"/>
    <field name="impression" class="java.lang.Integer"/>
    <field name="filter_start_date" class="java.util.Date"/>
    <field name="filter_end_date" class="java.util.Date"/>
    <field name="ctr" class="java.lang.Float"/>
    <field name="restaurantname" class="java.lang.String"/>
    <field name="medianame" class="java.lang.String"/>
    <variable name="RestaurantTotal" class="java.lang.Integer" resetType="Group" resetGroup="Restaurant Name" calculation="Sum">
        <variableExpression><![CDATA[$F{impression}]]></variableExpression>
    </variable>
    <variable name="RestaurantGrandTotal" class="java.lang.Integer" calculation="Sum">
        <variableExpression><![CDATA[$F{impression}]]></variableExpression>
    </variable>
    <variable name="CTR Total" class="java.lang.Float" resetType="Group" resetGroup="Restaurant Name" calculation="Sum">
        <variableExpression><![CDATA[$F{ctr}]]></variableExpression>
    </variable>
    <variable name="CTRGrandtotal" class="java.lang.Float" calculation="Sum">
        <variableExpression><![CDATA[$F{ctr}]]></variableExpression>
    </variable>
    <variable name="ClickTotal" class="java.lang.Integer" calculation="Sum">
        <variableExpression><![CDATA[$F{clicked}]]></variableExpression>
    </variable>
    <variable name="ClickGrandTotal" class="java.lang.Integer" resetType="Group" resetGroup="Restaurant Name" calculation="Sum">
        <variableExpression><![CDATA[$F{clicked}]]></variableExpression>
    </variable>
    <group name="Restaurant Name" isReprintHeaderOnEachPage="true">
        <groupExpression><![CDATA[$F{restaurantname}]]></groupExpression>
        <groupHeader>
            <band height="50">
                <staticText>
                    <reportElement mode="Opaque" x="0" y="30" width="149" height="20" forecolor="#FFFFFF" backcolor="#0FAAC2"/>
                    <textElement verticalAlignment="Middle">
                        <font fontName="Times New Roman" size="10" isBold="true"/>
                        <paragraph firstLineIndent="4"/>
                    </textElement>
                    <text><![CDATA[Advertise Name]]></text>
                </staticText>
                <staticText>
                    <reportElement mode="Opaque" x="412" y="30" width="46" height="20" forecolor="#FFFFFF" backcolor="#0FAAC2"/>
                    <textElement textAlignment="Center" verticalAlignment="Middle">
                        <font fontName="Times New Roman" size="10" isBold="true"/>
                    </textElement>
                    <text><![CDATA[Click]]></text>
                </staticText>
                <staticText>
                    <reportElement mode="Opaque" x="283" y="30" width="78" height="20" isPrintInFirstWholeBand="true" forecolor="#FFFFFF" backcolor="#0FAAC2"/>
                    <textElement verticalAlignment="Middle">
                        <font fontName="Times New Roman" size="10" isBold="true"/>
                        <paragraph firstLineIndent="2"/>
                    </textElement>
                    <text><![CDATA[AD Location]]></text>
                </staticText>
                <staticText>
                    <reportElement mode="Opaque" x="458" y="30" width="51" height="20" forecolor="#FFFFFF" backcolor="#0FAAC2"/>
                    <textElement textAlignment="Center" verticalAlignment="Middle">
                        <font fontName="Times New Roman" size="10" isBold="true"/>
                    </textElement>
                    <text><![CDATA[Impression]]></text>
                </staticText>
                <textField>
                    <reportElement x="0" y="10" width="284" height="20"/>
                    <textElement verticalAlignment="Middle">
                        <font isBold="true" isUnderline="false"/>
                    </textElement>
                    <textFieldExpression><![CDATA["Restaurant Name : "+ $F{restaurantname}]]></textFieldExpression>
                </textField>
                <staticText>
                    <reportElement mode="Opaque" x="149" y="30" width="134" height="20" isPrintInFirstWholeBand="true" forecolor="#FFFFFF" backcolor="#0FAAC2"/>
                    <textElement verticalAlignment="Middle">
                        <font fontName="Times New Roman" size="10" isBold="true"/>
                        <paragraph firstLineIndent="4"/>
                    </textElement>
                    <text><![CDATA[Campaign]]></text>
                </staticText>
                <staticText>
                    <reportElement mode="Opaque" x="509" y="30" width="46" height="20" forecolor="#FFFFFF" backcolor="#0FAAC2"/>
                    <textElement textAlignment="Center" verticalAlignment="Middle">
                        <font fontName="Times New Roman" size="10" isBold="true"/>
                    </textElement>
                    <text><![CDATA[CTR (%)]]></text>
                </staticText>
                <staticText>
                    <reportElement mode="Opaque" x="361" y="30" width="51" height="20" forecolor="#FFFFFF" backcolor="#0FAAC2"/>
                    <textElement verticalAlignment="Middle">
                        <font fontName="Times New Roman" size="10" isBold="true"/>
                        <paragraph firstLineIndent="4" leftIndent="10"/>
                    </textElement>
                    <text><![CDATA[Type]]></text>
                </staticText>
            </band>
        </groupHeader>
        <groupFooter>
            <band height="21">
                <textField pattern="###0.00">
                    <reportElement x="509" y="1" width="47" height="20"/>
                    <textElement textAlignment="Center" verticalAlignment="Middle">
                        <font fontName="Times New Roman"/>
                    </textElement>
                    <textFieldExpression><![CDATA[$V{ClickTotal}/$V{RestaurantTotal}*100]]></textFieldExpression>
                </textField>
                <textField>
                    <reportElement x="412" y="0" width="46" height="21"/>
                    <textElement textAlignment="Center" verticalAlignment="Middle">
                        <font fontName="Times New Roman" isBold="true"/>
                    </textElement>
                    <textFieldExpression><![CDATA[$V{ClickTotal}]]></textFieldExpression>
                </textField>
                <staticText>
                    <reportElement x="270" y="1" width="142" height="20"/>
                    <textElement textAlignment="Right" verticalAlignment="Middle">
                        <font fontName="Times New Roman" isBold="true"/>
                        <paragraph leftIndent="5"/>
                    </textElement>
                    <text><![CDATA[Group Total ]]></text>
                </staticText>
                <textField pattern="" isBlankWhenNull="true">
                    <reportElement x="458" y="1" width="51" height="20"/>
                    <textElement textAlignment="Center" verticalAlignment="Middle" markup="none">
                        <font fontName="Times New Roman" isBold="true"/>
                    </textElement>
                    <textFieldExpression><![CDATA[$V{RestaurantTotal}]]></textFieldExpression>
                </textField>
            </band>
        </groupFooter>
    </group>
    <background>
        <band splitType="Stretch"/>
    </background>
    <pageHeader>
        <band height="113">
            <image scaleImage="RetainShape" isUsingCache="true">
                <reportElement x="414" y="0" width="139" height="65"/>
                <imageExpression><![CDATA["C:\\Liferay\\tomcat-7.0.27\\webapps\\eMenuAdvertise-portlet\\img\\eMenuLogo.png"]]></imageExpression>
            </image>
            <textField pattern="MM/dd/yyyy h.mm a Z">
                <reportElement x="30" y="0" width="100" height="20"/>
                <textElement textAlignment="Justified">
                    <font fontName="Times New Roman" isUnderline="false"/>
                </textElement>
                <textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression>
            </textField>
            <textField pattern="MM/dd/yyyy">
                <reportElement x="30" y="93" width="64" height="20"/>
                <textElement textAlignment="Justified" verticalAlignment="Middle"/>
                <textFieldExpression><![CDATA[$F{filter_start_date}]]></textFieldExpression>
            </textField>
            <staticText>
                <reportElement x="0" y="0" width="30" height="20"/>
                <textElement>
                    <font fontName="Times New Roman" isBold="true"/>
                </textElement>
                <text><![CDATA[Date : ]]></text>
            </staticText>
            <staticText>
                <reportElement x="94" y="93" width="19" height="20"/>
                <textElement verticalAlignment="Middle">
                    <font isBold="true"/>
                </textElement>
                <text><![CDATA[To:]]></text>
            </staticText>
            <staticText>
                <reportElement x="0" y="93" width="30" height="20"/>
                <textElement verticalAlignment="Middle">
                    <font isBold="true"/>
                </textElement>
                <text><![CDATA[From:]]></text>
            </staticText>
            <textField pattern="MM/dd/yyyy">
                <reportElement x="113" y="93" width="100" height="20"/>
                <textElement textAlignment="Justified" verticalAlignment="Middle"/>
                <textFieldExpression><![CDATA[$F{filter_end_date}]]></textFieldExpression>
            </textField>
            <staticText>
                <reportElement x="130" y="23" width="283" height="67"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font fontName="Arial Black" size="16" isBold="true" isUnderline="false"/>
                </textElement>
                <text><![CDATA[Restaurant Report]]></text>
            </staticText>
        </band>
    </pageHeader>
    <columnHeader>
        <band/>
    </columnHeader>
    <detail>
        <band height="18" splitType="Immediate">
            <textField>
                <reportElement mode="Transparent" x="0" y="1" width="149" height="15"/>
                <textElement textAlignment="Left" verticalAlignment="Middle" markup="html">
                    <font fontName="Times New Roman" size="9"/>
                    <paragraph lineSpacing="Single" firstLineIndent="5"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{advertisename}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement mode="Transparent" x="283" y="1" width="78" height="15" backcolor="#FFFFFF"/>
                <textElement textAlignment="Left" verticalAlignment="Middle" markup="html">
                    <font fontName="Times New Roman" size="9"/>
                    <paragraph lineSpacing="Single" firstLineIndent="5"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{ad_location}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement mode="Transparent" x="458" y="1" width="51" height="15"/>
                <textElement textAlignment="Center" verticalAlignment="Middle" markup="html">
                    <font fontName="Times New Roman" size="9"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{impression}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement mode="Transparent" x="412" y="1" width="46" height="15"/>
                <textElement textAlignment="Center" verticalAlignment="Middle" markup="html">
                    <font fontName="Times New Roman" size="9"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{clicked}]]></textFieldExpression>
            </textField>
            <line direction="BottomUp">
                <reportElement x="0" y="16" width="555" height="1"/>
                <graphicElement>
                    <pen lineWidth="0.5" lineStyle="Solid"/>
                </graphicElement>
            </line>
            <textField>
                <reportElement x="149" y="1" width="134" height="15"/>
                <textElement textAlignment="Left" verticalAlignment="Middle">
                    <font fontName="Times New Roman" size="9"/>
                    <paragraph firstLineIndent="5"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{camp_name}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="509" y="1" width="46" height="15"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font fontName="Times New Roman" size="9"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{ctr}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="361" y="1" width="51" height="15"/>
                <textElement textAlignment="Left" verticalAlignment="Middle">
                    <font fontName="Times New Roman" size="9"/>
                    <paragraph firstLineIndent="5" leftIndent="10"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{medianame}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
    <columnFooter>
        <band/>
    </columnFooter>
    <pageFooter>
        <band height="23" splitType="Immediate">
            <textField>
                <reportElement x="226" y="0" width="80" height="20"/>
                <textElement textAlignment="Right" verticalAlignment="Middle">
                    <font fontName="Times New Roman" isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>
            </textField>
            <textField evaluationTime="Report">
                <reportElement x="308" y="0" width="40" height="20"/>
                <textElement verticalAlignment="Middle">
                    <font fontName="Times New Roman" isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
            </textField>
        </band>
    </pageFooter>
    <lastPageFooter>
        <band height="20" splitType="Immediate">
            <textField evaluationTime="Report">
                <reportElement x="308" y="0" width="40" height="20"/>
                <textElement verticalAlignment="Middle">
                    <font fontName="Times New Roman" isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="228" y="0" width="80" height="20"/>
                <textElement textAlignment="Right" verticalAlignment="Middle">
                    <font fontName="Times New Roman" isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>
            </textField>
        </band>
    </lastPageFooter>
    <summary>
        <band height="20">
            <staticText>
                <reportElement x="257" y="0" width="155" height="20"/>
                <textElement textAlignment="Right" verticalAlignment="Middle">
                    <font fontName="Times New Roman" size="11" isBold="true"/>
                    <paragraph rightIndent="5"/>
                </textElement>
                <text><![CDATA[Grand Total]]></text>
            </staticText>
            <textField pattern="###0" isBlankWhenNull="false">
                <reportElement x="458" y="0" width="51" height="20"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font fontName="Times New Roman" size="11" isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA[$V{RestaurantGrandTotal}]]></textFieldExpression>
            </textField>
            <textField pattern="###0.00">
                <reportElement x="509" y="0" width="45" height="20"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font fontName="Times New Roman" size="11" isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA[$V{ClickGrandTotal}/$V{RestaurantGrandTotal}*100]]></textFieldExpression>
            </textField>
            <textField pattern="###0">
                <reportElement x="412" y="0" width="46" height="20"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font fontName="Times New Roman" size="11" isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA[$V{ClickGrandTotal}]]></textFieldExpression>
            </textField>
        </band>
    </summary>
    <noData>
        <band/>
    </noData>
</jasperReport>

these is the properties i set before exporting to excel file

exporterXLS.setParameter(JRXlsExporterParameter.JASPER_PRINT,
                jasperPrint);
        exporterXLS.setParameter(JRXlsExporterParameter.OUTPUT_STREAM,
                byteArrayOutputStream);
        exporterXLS.setParameter(JRXlsExporterParameter.IS_IGNORE_CELL_BORDER,
                Boolean.FALSE);
        exporterXLS.setParameter(
                JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE);
        exporterXLS.setParameter(
                JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS,
                Boolean.TRUE);
        exporterXLS.setParameter(JRXlsExporterParameter.IS_COLLAPSE_ROW_SPAN,
                Boolean.TRUE);
        exporterXLS.setParameter(
                JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_COLUMNS,
                Boolean.TRUE);
        exporterXLS.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET,
                Boolean.FALSE);
        exporterXLS.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE,
                Boolean.FALSE);

        exporterXLS.setParameter(JRXlsExporterParameter.IS_IGNORE_GRAPHICS,
                Boolean.FALSE);

So can Anyone Please guide me that how can i export to Standard excel file from jasper with the image cell border and the excel file look likes normal excel file.**other problem is that **its not even coming in proper alignment .

With the Above Function i have set all parameter thats helps me to achieve this..posting this for the people who have still problems to export excel file with jasper.thanx

  private void SetExcelReportParameter(JRXlsExporter exporterXLS,
                JasperPrint jasperPrint, ByteArrayOutputStream byteArrayOutputStream) {

            exporterXLS.setParameter(JRXlsExporterParameter.JASPER_PRINT,
                    jasperPrint);
            exporterXLS.setParameter(JRXlsExporterParameter.OUTPUT_STREAM,
                    byteArrayOutputStream);
            exporterXLS.setParameter(JRXlsExporterParameter.IS_IGNORE_CELL_BORDER,
                    Boolean.FALSE);
            exporterXLS.setParameter(
                    JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE);
            exporterXLS.setParameter(
                    JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS,
                    Boolean.TRUE);
            exporterXLS.setParameter(JRXlsExporterParameter.IS_COLLAPSE_ROW_SPAN,
                    Boolean.TRUE);

            exporterXLS.setParameter(
                    JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_COLUMNS,
                    Boolean.TRUE);
            exporterXLS.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET,
                    Boolean.FALSE);
            exporterXLS.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE,
                    Boolean.TRUE);

            exporterXLS.setParameter(JRXlsExporterParameter.IS_IMAGE_BORDER_FIX_ENABLED,
                    Boolean.TRUE);
            exporterXLS.setParameter(JRXlsExporterParameter.IS_FONT_SIZE_FIX_ENABLED,
                    Boolean.TRUE);

            exporterXLS.setParameter(JRXlsExporterParameter.IS_IGNORE_GRAPHICS,
                    Boolean.FALSE);

        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM