ExcelUtils工具推荐

本文介绍ExcelUtils,一种专门用于处理Excel文件的报表生成工具。通过使用Excel文件作为模板,并结合简单的定义语言,可以轻松实现数据填充及复杂报表的生成。本文还提供了一个简单的示例,展示如何使用Java代码将数据填充到Excel模板中。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ExcelUtils代表着一类的报表生成工具,他使用报表本身作为模板。对于它,只能处理Excel文件,它以Excel文件为模板,在其上加以自己的定义语言,简单通俗!
官方主页:http://excelutils.sourceforge.net/Overview.html

 

  • ${model.name} means getting property of the name from the model object.
  • ${!model.name} means that last cell and this cell merge if model.name value equals last cell value.
  • #foreach model in ${list},means that iterate list,modelId is implied index of the list.
  • #each ${model} ${width1},${width2} on ${keys},model can be a Map,JavaBean,Collection or Array object, #each key
    will show all property of the model.${width?} means merge ${width?} cells. If only one
    width, all property use the same width. If more than one, use the witdh in order, not set will use "1".${keys} can be Map,Array,List which contain field's name you want to display, it's not required.
  • ${list[0].name} means get the first object from list, then read the property of name.
  • ${map(key)} get the value from the map by the key name.
  • ${list[${index}].name} [] can be a variable.
  • ${map(${key})} () can be a vriable.
  • #sum qty on ${list} where name like/=str sum qty on ${list} collection by where condition.
  • In net.sf.excelutils.tags Package, you can implement ITag to exentd Tag key. eg, FooTag will parse #foo.
  • ExcelResult for webwork.
  • ${model${index}} support.
  • #call service.method("str", ${name}) call a method
  • #formual SUM(C${currentRowNo}:F${currentRowNo}) means output excel formula SUM(C?:F?) ? means currentRowNo.
  • #page tag to split page.
  • #if tag support beanshell scripts.

    示例:
    模板:

    转化代码:
    public class Main {

    /**
    * @param args
    */
    public static void main(String[] args) {
       String[][] datas = { { "001", "张三" }, { "002", "李四" }, { "003", "王五" } };
       ExcelUtils.addValue("datas", datas);
       String config = "template/t1.xls";
       try {
        FileOutputStream fo = new FileOutputStream("result.xls");
        ExcelUtils.export(config, fo);
       } catch (ExcelException e) {
        e.printStackTrace();
       } catch (FileNotFoundException e) {
        e.printStackTrace();
       }
    }

    }

    结果输出的excel:

 

We're headache on making web report all long. ExcelUtils is a helper to export excel report in java web project. It's like velocity, has own tags, but these tags is written in excel file. By these tags, you can custom your excel report format freely, not edit any your source, just ExcelUtils parses your excel template and fills values to export your report. It is based POI project and beanutils project. It uses excel and template language's profit to make web reports easily. After my hardwork, the parser is finished finally, in which report is exported by Excel Template. It's funtions include: 1、${model.name} means getting property of the name from the model object. 2、${!model.name} means that last cell and this cell merge if model.name value equals last cell value. 3、#foreach model in ${list},means that iterate list,modelId is implied index of the list. 4、#each ${model} ${width1},${width2},model can be a Map,JavaBean,Collection or Array object, #each key will show all property of the model.${width?} means merge ${width?} cells. If only one width, all property use the same width. If more than one, use the witdh in order, not set will use "1". 5、${list[0].name} means get the first object from list, then read the property of name. 6、${map(key)} get the value from the map by the key name. 7、${list[${index}].name} [] can be a variable. 8、${map(${key})} () can be a vriable. 9、#sum qty on ${list} where name like/=str sum qty on ${list} collection by where condition. 10、In net.sf.excelutils.tags Package, you can implement ITag to exentd Tag key. eg, FooTag will parse #foo. 11、ExcelResult for webwork. 12、${model${index}} support. 13、#call service.method("str", ${name}) call a method 14、#formual SUM(C${currentRowNo}:F${currentRowNo}) means output excel formula SUM(C?:F?) ? means currentRowNo.
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值