2017-04-24 59 views
0

的我更新來自4.8.0JasperReports的6.3.0版本。JasperReports的6.x的:改用棄用JRTextExporterParameter.LINE_SEPARATOR

但是出口商沒有像setLineSeparator這樣的方法。 JRTextExporter.setParameter(JRTextExporterParameter.LINE_SEPARATOR)已棄用。

設置這樣不起作用:

Exporter exporter = new JRTextExporter(); 
((JRTextExporter)exporter).getParameters().put(JRTextExporterParameter.LINE_SEPARATOR, "\r\n"); 
exporter.setExporterOutput(new SimpleWriterExporterOutput(outputFile, characterEncodingProp)); 

設置在JRXML屬性也不起作用:

<property name="net.sf.jasperreports.export.text.line.separator" value="&#xD;&#xA;"/> 

<property name="net.sf.jasperreports.export.text.line.separator" value="\r\n"/> 

如何設置線分隔器?

回答

1

,而不是使用過時JRTextExporterParameter.LINE_SEPARATOR屬性我們應該用TextExporterConfiguration.getLineSeparator方法。

在使用的情況下SimpleTextExporterConfiguration(這是具體落實TextExporterConfiguration接口)類的代碼將是這樣的:

JRExporter exporter = new JRTextExporter(); 

SimpleTextExporterConfiguration configuration = new SimpleTextExporterConfiguration(); 
configuration.setLineSeparator("#"); 

exporter.setConfiguration(configuration); 

exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); 
exporterOutput = new SimpleWriterExporterOutput(file); 
exporter.setExporterOutput(exporterOutput); 
exporter.exportReport(); 

隨着net.sf.jasperreports.export.text.character.widthnet.sf.jasperreports.export.text.character.height幫助我們可以設置字符的寬度和高度。

JRXML頭的片段:

<?xml version="1.0" encoding="UTF-8"?> 
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" ..> 
    <property name="net.sf.jasperreports.export.text.character.width" value="7.2"/> 
    <property name="net.sf.jasperreports.export.text.character.height" value="14.0"/> 
+0

我使用了SimpleTextReportConfiguration。我也需要像 configuration.setCharWidth(10f); configuration.setCharHeight(20f); 但SimpleTextExporterConfiguration沒有這些方法。 – OGSL

+0

這是另一個問題,但我添加了信息到我的文章:) –

0

感謝的。這樣的代碼也解決了任務:

Exporter exporter = new JRTextExporter(); 
final SimpleTextReportConfiguration txtConfiguration = new SimpleTextReportConfiguration(); 
txtConfiguration.setCharWidth(10f); 
txtConfiguration.setCharHeight(20f); 
exporter.setConfiguration(txtConfiguration); 
SimpleTextExporterConfiguration configuration = new SimpleTextExporterConfiguration(); 
configuration.setLineSeparator("\r\n"); 
exporter.setConfiguration(configuration); 
相關問題