最近遇到导出excel的需求,系统已经有了基于jasperreports制导出pdf的功能(模板是jaspersoft report制作的),图省事直接利用jasperreports的方法来导出excel。单导出的excel没有去掉grid line十分难看。后来查了一下,要去掉grid line很简单。
方式一:直接在jrxml的文件里配置
<property name="net.sf.jasperreports.export.xls.show.gridlines" value="false"/>
方式二:在代码里配置
JRXlsxExporter exporter = new JRXlsxExporter();
exporter.setExporterInput(SimpleExporterInput.getInstance(sheets1));
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(new File("test.xlsx"));
SimpleXlsxReportConfiguration configuration = new SimpleXlsxReportConfiguration();
configuration.setShowGridLines(Boolean.FALSE);
configuration.setOnePagePerSheet(Boolean.FALSE);
configuration.setRemoveEmptySpaceBetweenColumns(true);
configuration.setWhitePageBackground(Boolean.FALSE);
exporter.setConfiguration(configuration);
exporter.exportReport();
最后上一张图看看什么是excel的grid line,就是下面红框标记的部分

导出的excel去掉grid line的样子

本文介绍如何在使用jasperreports导出Excel时去除网格线(gridline),提供两种方法:一是修改jrxml文件配置,二是通过代码设置。通过具体代码示例展示了如何实现这一功能,改善了导出Excel的美观度。

1万+

被折叠的 条评论
为什么被折叠?



