我正在尝试通过 JasperReports API 将报告导出到xls。数据库用俄语显示日期,我需要用俄语 但是在导出的xls文件中,Date是英文的 我尝试将Locale插入到报表参数图中,
Locale locale = new Locale("ru", "RU");
parameters.put(JRParameter.REPORT_LOCALE, locale);
但似乎问题出在导出上,而不是生成
我做错了什么?
示例jrxmpl模板是:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport ...>
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<property name="net.sf.jasperreports.print.keep.full.text" value="true"/>
<field name="Time" class="java.lang.String"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="168" splitType="Stretch">
<textField pattern="dd/MM/yyyy HH.mm.ss">
<reportElement x="400" y="90" width="160" height="24" uuid="22c78122-f74b-482a-9642-088d474a9f62"/>
<textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="480" y="114" width="80" height="54" uuid="58989dd8-a634-49bc-93cc-3102a94f600a"/>
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="10" isBold="true"/>
</textElement>
<text><![CDATA[Time]]></text>
</staticText>
</band>
</title>
<detail>
<band height="20" splitType="Stretch">
<textField isBlankWhenNull="false">
<reportElement x="480" y="0" width="80" height="20" uuid="db69c959-5302-4d06-ba5c-413cd2aa78ed"/>
<box>
<topPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{Time}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
示例java代码是:
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
String resource = null;
ps = con.prepareStatement("SELECT (TIME, 'dd MONTH yyyy HH24:mm') TIME FROM base");
rs = ps.executeQuery();
InputStream is = new FileInputStream(pathToReportsTemplates + "/"
+ reportName + ReportConstants.TEMPLATE_FILE_EXTENSION);
JasperReport report = JasperCompileManager.compileReport(is);
Map parameters = new HashMap();
Locale locale = new Locale("ru", "RU");
parameters.put(JRParameter.REPORT_LOCALE, locale);
JasperPrint print = JasperFillManager.fillReport(report,
parameters, new JRResultSetDataSource(rs));
JRXlsExporter exporter = new JRXlsExporter();
exporter.setExporterInput(new SimpleExporterInput(print));
SimpleXlsReportConfiguration configuration = new SimpleXlsReportConfiguration();
configuration.setOnePagePerSheet(false);
exporter.setConfiguration(configuration);
File myPath = new File(outputPath);
String fullPathToOutputFile = outputPath + "/" + reportName + "-"
+ newTimestamp + ".xls";
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(
fullPathToOutputFile));
exporter.exportReport();