JasperReports导出到excel auto size列 [英] JasperReports export to excel auto size columns

查看:119
本文介绍了JasperReports导出到excel auto size列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到JRXlsExporter的问题。自动调整属性无法正常工作。
这是我的jrxml:

I have a problems with JRXlsExporter. Autofit properties not work correctly. Here is my jrxml:

<?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="templ" language="groovy" pageWidth="1100" pageHeight="1400" columnWidth="1060" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isSummaryNewPage="true" isSummaryWithPageHeaderAndFooter="true" uuid="683fcccd-cd5a-4e1d-a085-b49c54c13fff">
    <property name="ireport.zoom" value="1.2100000000000029"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="0"/>
    <property name="net.sf.jasperreports.export.xls.detect.cell.type" value="true"/>
    <property name="net.sf.jasperreports.print.keep.full.text" value="true"/>
    <property name="net.sf.jasperreports.export.xls.wrap.text" value="false"/>
    <property name="net.sf.jasperreports.export.xls.auto.fit.row" value="true"/>
    <property name="net.sf.jasperreports.export.xls.auto.fit.column" value="true"/>
    <queryString language="SQL">
        <![CDATA[]]>
    </queryString>
</jasperReport>

Java代码:

excelExporter.setParameter(JRXlsExporterParameter.JASPER_PRINT, jasperPrint);
excelExporter.setParameter(JRXlsExporterParameter.OUTPUT_STREAM, outputStream);
excelExporter.setParameter(JRXlsExporterParameter.MAXIMUM_ROWS_PER_SHEET, 65536);
excelExporter.setParameter(JRXlsExporterParameter.IS_IGNORE_CELL_BORDER, Boolean.FALSE);
excelExporter.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE);
excelExporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
excelExporter.setParameter(JRXlsExporterParameter.IS_COLLAPSE_ROW_SPAN, Boolean.TRUE);
excelExporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_COLUMNS, Boolean.TRUE);
excelExporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE);
excelExporter.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE, Boolean.TRUE);
excelExporter.setParameter(JRXlsExporterParameter.IS_IMAGE_BORDER_FIX_ENABLED, Boolean.TRUE);
excelExporter.setParameter(JRXlsExporterParameter.IS_IGNORE_GRAPHICS, Boolean.FALSE);

和输出结果:
resultFile

例如,第一列必须是客户编号而不是客户

For example first column must be "Customer Number" instead of "Custome"

推荐答案

以下属性不适用于报表级别:

The following properties do not work on Report Level:

<property name="net.sf.jasperreports.export.xls.auto.fit.row" value="true"/>
<property name="net.sf.jasperreports.export.xls.auto.fit.column" value="true"/>

您必须将它们放在报表元素上(即):

You have to put them on Report Elements (i.e.):

        <staticText>
            <reportElement x="0" y="100" width="100" height="20">
                <property name="net.sf.jasperreports.export.xls.auto.fit.row" value="true"/>
                <property name="net.sf.jasperreports.export.xls.auto.fit.column" value="true"/>
            </reportElement>
            <textElement/>
            <text><![CDATA[Your Static Text]]></text>
        </staticText>

此外,我建议您尝试使用net.sf.jasperreports.export.xls.column。 width属性,更有用。参考: http://jasperreports.sourceforge.net/config.reference.html

Also I'd recommend you to try using net.sf.jasperreports.export.xls.column.width property, which is more useful. Reference: http://jasperreports.sourceforge.net/config.reference.html

这篇关于JasperReports导出到excel auto size列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆