2015-12-06 73 views
2

我们使用的是jasper版本6.我们可以导出到EXCEL(XLS和XLSX)。Jasper Report如何使用RTL工作表创建excel xlsx文件?

下面的代码适用于XLS并创建一个RTL表:

exporter = new JRXlsExporter(); 
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(out)); 
SimpleXlsReportConfiguration xlsReportConfig = new SimpleXlsReportConfiguration(); 
xlsReportConfig.setSheetDirection(RunDirectionEnum.RTL); 
exporter.setConfiguration(xlsReportConfig);  

然而,当我尝试同样的代码,以使一个XLSX文件纸张方向不会改变RTL:

exporter = new JRXlsxExporter(); 
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(out)); 
SimpleXlsxReportConfiguration xlsxReportConfiguration = new SimpleXlsxReportConfiguration(); 
xlsxReportConfiguration.setSheetDirection(RunDirectionEnum.RTL); 
exporter.setConfiguration(xlsxReportConfiguration); 
+0

这是碧玉报告,您已经厌倦了?发现同样的bug的确切版本为V 6.1.1 –

回答

1

似乎是错误碧玉报告库测试与v 6.1.1,添加代码后导出它会正常工作(wi包括在碧玉报告分发中的第二个poi库,所以POI没有错误...)。

//out is the file after jasper report export 
XSSFWorkbook workbook = new XSSFWorkbook(new FileInputStream(out)); 
int ns = workbook.getNumberOfSheets(); 
for (int i = 0; i < ns; i++) { 
    XSSFSheet sheet = workbook.getSheetAt(i); 
    sheet.setRightToLeft(true); 
} 
FileOutputStream outStream = new FileOutputStream(out); 
workbook.write(outStream); 
outStream.close(); 

Current bug report tracker on jaspersoft community

0

我有一个问题产生在XLSX的报告显示,JasperReports的6.1的最后一个版本,但此代码的工作对我来说:

首先,我配置碧玉打印

JRSwapFile swapFile = new JRSwapFile(".", 1024, 1024); 
    JRVirtualizer virtualizer = new JRSwapFileVirtualizer(100, swapFile, true); 
    parameters.put(JRParameter.REPORT_VIRTUALIZER, virtualizer); 

    JasperPrint print = JasperFillManager.fillReport(stream, parameters, dbConnection); 
    List<JasperPrint> prints = new ArrayList<JasperPrint>(); 
    prints.add(print); 

之后,我为生成的报告配置输出,在我的情况下,报告将通过ByteArrayOutputStream在内存中管理:

ByteArrayOutputStream output = new ByteArrayOutputStream(); 

我创建生成与.xslx扩展名的文件JRXlsxExporter的一个实例,并把打印机和输出:

JRXlsxExporter exporter = new JRXlsxExporter(); 
    exporter.setExporterInput(SimpleExporterInput.getInstance(prints)); 
    exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(output)); 

下一个步骤是创建报告配置出口当我把这个代码我报告工作!所以你必须使用它!:

SimpleXlsxReportConfiguration xlsxReportConfiguration = new SimpleXlsxReportConfiguration(); 
    xlsxReportConfiguration.setSheetDirection(RunDirectionEnum.RTL); 
    exporter.setConfiguration(xlsxReportConfiguration); 

最后,生成报告和关闭的OutputStream:

exporter.exportReport(); 
    output.flush(); 
    output.close(); 

我希望这对你的作品

相关问题