jasper-reports
xls / xlsx로 내보내기
수색…
Java 사용
xlsx 형식으로 내보내기
try (InputStream inputStream = JRLoader.getResourceInputStream(path)) { // read report as input stream
JasperReport jasperReport = JasperCompileManager.compileReport(JRXmlLoader.load(inputStream)); // compile report
Map<String, Object> params = new HashMap<>(); // init map with report's parameters
params.put(JRParameter.REPORT_LOCALE, Locale.US);
params.put(JRParameter.IS_IGNORE_PAGINATION, true);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, connection); // prepare report - passs parameters and jdbc connection
JRXlsxExporter exporter = new JRXlsxExporter(); // initialize exporter
exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); // set compiled report as input
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(destFile)); // set output file via path with filename
SimpleXlsxReportConfiguration configuration = new SimpleXlsxReportConfiguration();
configuration.setOnePagePerSheet(true); // setup configuration
configuration.setDetectCellType(true);
exporter.setConfiguration(configuration); // set configuration
exporter.exportReport();
}
열의 자동 필터 추가하기
net.sf.jasperreports.export.xls.auto.filter 속성을 사용하면 생성 된 xls 파일에 자동 필터를 추가 할 수 있습니다.
<columnHeader>
<band height="30" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="100" height="20">
<property name="net.sf.jasperreports.export.xls.auto.filter" value="Start"/>
</reportElement>
<text><![CDATA[First column with filter]]></text>
</staticText>
<staticText>
<reportElement x="100" y="0" width="100" height="20"/>
<text><![CDATA[Second column with filter]]></text>
</staticText>
<staticText>
<reportElement x="200" y="0" width="100" height="20">
<property name="net.sf.jasperreports.export.xls.auto.filter" value="End"/>
</reportElement>
<text><![CDATA[Third (Last) column with filter]]></text>
</staticText>
<staticText>
<reportElement x="300" y="0" width="100" height="20"/>
<text><![CDATA[Fourth column without filter]]></text>
</staticText>
</band>
</columnHeader>
이 속성은 컨텍스트 메뉴의 도움으로 Jaspersoft Studio 에서 설정하거나 jrxml 파일을 수동으로 편집하여 설정할 수 있습니다.
Modified text is an extract of the original Stack Overflow Documentation
아래 라이선스 CC BY-SA 3.0
와 제휴하지 않음 Stack Overflow
