ExcelUtils工具推薦

來源:互聯網
上載者:User

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:

  •  

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.