egg-szjcomo-excel

1.0.5 • Public • Published

egg-szjcomo-excel

NPM version build status Test coverage David deps Known Vulnerabilities npm download

Install

$ npm i egg-szjcomo-excel --save

Usage

// {app_root}/config/plugin.js
exports.excel = {
  enable: true,
  package: 'egg-szjcomo-excel',
};

Configuration

// {app_root}/config/config.default.js
exports.excel = {
};

see config/config.default.js for more detail.

Example

读取excel表格

read方法

read function(filename,options = {},index_sheet = 0)
参数名称 类型 是否必须 备注
filename string -(表格名称,只能为xlsx格式的表格文件)
options object - {fields:[],skip:0}
index_sheet int - 读取表格里面的第几张表 default:0

用法示例

const headers = ['school_name','password','','admin_id'];
console.log(app.excel.read('test.xlsx',{fileds:headers,skip:0},0));

特列说明

options.fields 为列参应的字典下标 options.skip 为需要跳过的行


写入excel表格

write方法

write function(data,filename,headers = [],options = {},cusTitle = [])
参数名称 类型 是否必须 备注
data array -写入数据
filename string - (表格名称,只能为xlsx格式的表格文件)
headers array - 表头自动生成
options object - 参见 node-xlsx参数
cusTitle array - 不需要自动生成,手动自定义

简单用法

	let data = [{name:'szjcomo',idcardno:'123456'}];
	let headers = [{name:'用户名',key:'name'},{name:'身份证号',key:'idcardno'}];
	app.excel.write(data,'test.xlsx',headers)

复杂用法

let data = [{name:'szjcomo',idcardno:'123456',id:1}];
let headers = [{name:'序号',key:'id'},{name:'用户名',key:'name'},{name:'身份证号',key:'idcardno'}];
let cusTitle = [['序号','详细信息'],['','用户名','身份证号']];
let options = {'!merges':[{s:{c:0,r:0},e:{c:0,r:1}},{s:{c:1,r:0},e:{c:2,r:0}}]};
app.excel.write(data,'test.xlsx',headers,options,cusTitle)

Questions & Suggestions

Please open an issue here.

License

MIT

Package Sidebar

Install

npm i egg-szjcomo-excel

Weekly Downloads

0

Version

1.0.5

License

MIT

Unpacked Size

12 kB

Total Files

6

Last publish

Collaborators

  • como20170606