egg-szjcomo-excel
v1.0.5
Published
egg szjcomo excel
Downloads
3
Readme
egg-szjcomo-excel
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.