Excel报表框架(ExcelReport)极简化解决复杂报表导出问题

Excel Report

耗费了半个月的时间,终于在元旦这三天把报表框架开发完成了,使用该框架你可以非常方便的导出复杂的Excel报表

项目开源地址:

前言

不知道各位在使用POI开发报表导出过程中遇到过以下的情况:

  1. 频繁的使用中间变量记录报表数据写到那个Cell中了。
  2. 一个复杂的报表往往至少要几百行、甚至是上千行的代码。
  3. POI的api非常难用,设置一个值甚至绘制一个图形要调用好多类
  4. 为Cell设置Style非常麻烦,还得时时担心style数量会不会超过excel的最大限制
  5. merge Cell的时候提心吊胆的,得谨慎小心的计算应该merge的cell范围

等等等等,上面的这些内容我估计频繁开发复杂报表的同学应该非常熟悉,这些还不是最痛苦的,最痛苦的是遇到那种报表修改的情况,假如某一个地方要加一列,某个地方要合并一个列,就必须把这成百上千的代码逻辑再次梳理一遍,因为所有的cell位置都是相关的,加了一列就必须把相关的cell位置也更新才可以。

复杂报表框架 Excel-Report

鉴于上面这种复杂报表的导出问题,花了半个月的时间,开发了一个复杂报表导出框架。它可以让我们像设计UI界面那样简单。

框架的特点:

  1. 几乎完全屏蔽POI操作,提供类UI框架的操作接口、定义报表非常简单
  2. 提供模板文件定义,类似于各种模板框架,支持SPEL表达式的模板定义
  3. 提供类似于 Themleaf 的 If, For 标签,更方便定义模板
  4. 自动计算组件位置
  5. 简化CellStyle设置
  6. 支持各种不同类型的组件(例如Text,List、Image,Link、Table、Chart…)

适合做什么

  • 比较复杂的各种嵌套的报表
  • 经常有可能会变化的报表
  • 单元格样式比较多的报表

不适合做什么

  • 大数据量的数据导出
    因为该框架是基于模板的报表生成框架,也就意味着要想让表达式工作就需要把数据加载到内存中才可以,所以大数据量的数据导出不适合用这个框架去做。
  • 非常简单的报表
    比如一个报表可能就一个table,一个list,这种方式用框架反而可能适得其反,阿里的easyexcel导出这类的报表更简单。

下面看看使用这个框架之后将会怎么简化报表的导出:

引入依赖

<dependency>
    <groupId>io.github.mengfly</groupId>
    <artifactId>excel-report</artifactId>
    <version>1.0.0</version>
</dependency>

定义报表组件(Java代码方式)

框架提供了类似的UI编程的方式,如果大家有接触过UI框架,那么对这些操作应该比较熟悉。

// 垂直布局
VLayout layout = new VLayout();

layout.addItem(new TextComponent(new Size(10, 5), "Test(width=10, height=5)"));
// 添加一个横向布局
final HLayout hLayout = layout.addItem(new HLayout());

final TextComponent item = new TextComponent(new Size(3, 1), "Test(width=3)");
// 设置样式
item.addStyle(CellStyles.fontColor, CellStyles.createColor(0xff0000));
item.addStyle(CellStyles.fontBold, true);
item.addStyle(CellStyles.fontName, "楷体");

hLayout.addItem(item);
hLayout.addItem(new TextComponent(new Size(5, 1), "Test(width=5)"));

这样就定义好了一个非常简单的组件。

下面可以通过一下代码导出excel

ExcelReport report = new ExcelReport();
report.exportSheet("sheet1", layout, SheetStyles.DEFAULT_STYLE);
report.save(new File("test.xlsx");

这样就生成了一个自定义布局的Excel。
在这里插入图片描述

定义报表组件(模板方式、推荐)

定义模板

首先编辑一个报表模板,只需要引入对应的命名空间就会有输入提示,如下:
在这里插入图片描述

以下为实例:

具体的模板实例可以参考:模板文件

<?xml version="1.0" encoding="UTF-8" ?>
<template
        xmlns="http://mengfly.github.io/excel-report/1.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://mengfly.github.io/excel-report/1.0.0 https://mengfly.github.io/xsd/excel-report-1.0.0.xsd"
        name="testImage"
        description="测试模板"
        version="1.0"
        author="MengFly"
        createAt="2023-12-26">

    <!--  定义模板参数,该参数无特殊意义,只是为了统一放在这里方便对模板内的参数统一展示,方便了解模板参数数据  -->
    <parameters>
        <parameter id="parameter" name="参数名称"/>
    </parameters
Excel Report BuilderExcel Report 万能报表平台Excel 使用WEB服务(webservice)访问远程数据库使用本软件可以使你的应用系统(数据库)excel相连。可以把它嵌入到你的应用系统里,做为应用系统的外挂程序。可以利用excel强大的编辑功能,随心所欲地开发出精美的报表。本软件基于Web Service(Web服务)新技术,所以它支持web网络,可以通过Internet访问远程数据。只要你稍懂SQL,就可以在Excel Report 万能报表平台上设计报表。通过设置字段,参数等信息来设计报表。BI智能报表,支持透视表。提供存储过程接口,便于用户二次开发。有用户管理,报表权限的管理。支持多语种。 软件环境: 客户端: Windows 2000及以上版本,Microsoft Office 2000及以上版本 服务器端:Windows和Linux都可以,jsdk1.4,tomcat5 数据库:支持Oracle, SQL Server 等数据库。下载地址: http://203.208.248.203:81/pan/Excel/Excel_Report_Setup.rar相关软件下载地址: Jdk 1.4:http://203.208.248.203:81/pan/Excel/j2sdk-1_4_2_06-windows-i586-p.exeTomcat5:http://203.208.248.203:81/pan/Excel/jakarta-tomcat-5.0.27.exe SQL Server SP3:http://203.208.248.203:81/pan/Excel/sql2ksp3.exeSQL Server SP4:http://download.microsoft.com/download/9/b/f/9bff6646-2cdb-4069-ada0-548be9cb9338/SQL2000-KB884525-SP4-x86-CHS.EXE联系方式: http://pansoft.ik8.com QQ: 10124900MSN: bear_pan@hotmail.comE_Mail: bear_pan@163.comExcel Report BuilderExcel Report Builder is an easy and convenient tool for the creation and customization of reports which takes advantage of the formatting and presentation capabilities of Microsoft Excel. The program allows the rapid construction of reports.A GUI style design environment, which allows the user to design their reports visually inside MS Excel. Reports can be saved and then viewed and printed as pure Excel documents. The reports are created and printed rapidly.In fact, it is by harnassing the power of Excel that gives Excel Report Builder these abilities.No technical knowledge is needed in order for the user to customise his or her own reports. Key Features of the Database Report Builder for Excel include: Report creation using Microsoft Excel Get data through webservice,so you can get remote data Support of the SQL-queries for the data sets creation Calling of the stored procedures for the data sets creation Creation of the reports with parameters Work with the Microsoft Excel macros Charts creation in a reportSoftware: Client: Windows 2000 or above,Microsoft Office 2000 or above Server: jsdk1.4,tomcat5 Database: Oracle or SQL Server Download: http://203.208.248.203:81/pan/Excel/Excel_Report_Setup.rarOther Softwares: Jdk 1.4:http://203.208.248.203:81/pan/Excel/j2sdk-1_4_2_06-windows-i586-p.exeTomcat5:http://203.208.248.203:81/pan/Excel/jakarta-tomcat-5.0.27.exeSQL Server SP3:http://203.208.248.203:81/pan/Excel/sql2ksp3.exeSQL Server SP4:http://download.microsoft.com/download/9/b/f/9bff6646-2cdb-4069-ada0-548be9cb9338/SQL2000-KB884525-SP4-x86-CHS.EXEContact: http://pansoft.ik8.com QQ: 10124900MSN: bear_pan@hotmail.comE_Mail: bear_pan@163.com
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值