Coder Social home page Coder Social logo

ejsexcel's Introduction

ejsExcel

nodejs excel template engine. node export excel, ejsExcel

How to use?

npm install ejsexcel

How to test?

  • 执行 test/test.bat

    test/test.bat
  • test/test.xlsx 为完整示例 demo

  • e.g

     const ejsexcel = require("ejsexcel");
     const fs = require("fs");
     const util = require("util");
     const readFileAsync = util.promisify(fs.readFile);
     const writeFileAsync = util.promisify(fs.writeFile);
     
    (async function() {
      //获得Excel模板的buffer对象
      const exlBuf = await readFileAsync("./test.xlsx");
      //数据源
      const data = [];
      //用数据源(对象)data渲染Excel模板
      //cachePath 为编译缓存路径, 对于模板文件比较大的情况, 可显著提高运行效率, 绝对路径, 若不设置, 则无缓存
      const exlBuf2 = await ejsexcel.renderExcel(exlBuf, data, { cachePath: __dirname+"/cache/" });
      await writeFileAsync("./test2.xlsx", exlBuf2);
      console.log("生成test2.xlsx");
    })();

Syntax

Syntax Description
data data 为内置对象, 数据源
<%forRow 循环一行
<%# 输出动态公式
<%~ 输出数字类型格式
<%= 输出字符串
<%forCell 循环单元格
<%forRBegin 循环多行
<%forCBegin 循环多个单元格
<%hideSheet()%> 隐藏所在工作表
<%showSheet()%> 显示所在工作表
<%deleteSheet()%> 删除所在工作表
<% %> 内部可执行 任意 javascript,可以用 <%console.log(data)%> 打印临时变量到控制台,进行调试

Author

Templates

做一个这样的模版 模板

Result

加数据渲染之后,导出结果

导出结果

捐赠鼓励支持此项目,支付宝扫描:

捐赠鼓励支持此项目

项目贡献人列表

  • @Hello World ¥50
  • @德爾文 ¥50
  • @Explore® ¥50
  • @向左转 ¥50
  • @吴燕飞 ¥50
  • @strive-ming ¥10
  • @MR.P ¥16.66
  • @不求来生 ¥6.60
  • @羊刀 ¥6.66
  • @Leo ¥8.88
  • @不摇碧莲 ¥6.66
  • @天涯海角 ¥10
  • @刚刚好 ¥5
  • @Aptenodytes forsteri ¥15
  • @HHB ¥30
  • @Original ¥88.88
  • @半日 ¥10

ejsexcel's People

Contributors

sail-sail avatar kirning avatar ghost141 avatar bryant1410 avatar sylarlong avatar cangzhen avatar kateier avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.