gpt4 book ai didi

java - Jasper Report 如何使用 RTL 表创建 excel xlsx 文件?

转载 作者:行者123 更新时间:2023-11-30 10:53:10 24 4
gpt4 key购买 nike

我们使用的是 jasper 版本 6。我们可以导出到 EXCEL(XLS 和 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);

最佳答案

我最终使用了下面的代码(它很昂贵但有效),在 https://community.jaspersoft.com/questions/523041/right-left-arabic-reports 中提到

public class ReportUtils {

private ReportUtils(){

}
/**
* mirror each page layout
* @param print
*/
public static void mirrorLayout(JasperPrint print) {
int pageWidth = print.getPageWidth();
for (Object element : print.getPages()) {
JRPrintPage page = (JRPrintPage) element;
mirrorLayout(page.getElements(), pageWidth);
}
}

/**
* mirror a list of elements
* @param print
*/
protected static void mirrorLayout(List<?> elements, int totalWidth) {
for (Iterator<?> it = elements.iterator(); it.hasNext();) {
JRPrintElement element = (JRPrintElement) it.next();
int mirrorX = totalWidth - element.getX() - element.getWidth();
element.setX(mirrorX);

if (element instanceof JRPrintFrame) {
JRPrintFrame frame = (JRPrintFrame) element;
mirrorLayout(frame.getElements(), frame.getWidth());
}
}
}
}

像这样使用它:

Exporter exporter;

ByteArrayOutputStream out = new ByteArrayOutputStream();
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(out));

JasperPrint jasperPrint = JasperFillManager.fillReport(report,
params, dataSource != null ? new JRMapArrayDataSource(
dataSource) : new JREmptyDataSource());
ReportUtils.mirrorLayout(jasperPrint);

exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
exporter.exportReport();
return out.toByteArray();

关于java - Jasper Report 如何使用 RTL 表创建 excel xlsx 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34116925/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com