ph-export
v1.0.0
Published
xls csv export js
Downloads
1
Readme
🚀 Welcome to your new awesome project!
This project has been created using webpack-cli, you can now run
npm install ph-export
usage
<button data-export="xls">xls</button>
<button data-export="cvs">cvs</button>
import { export2csv,export2xls } from 'ph-export'
interface Row{
name:string,
age:number,
gender:string,
[k:string]:any
}
const headers = [
{name:"姓名",key:"name"},
{name:"年龄",key:"age"},
{name:"性别",key:"gender"}
]
const list:Array<Row> = [{
name:"章三",
age:21,
gender:"男"
},{
name:"里四",
age:17,
gender:"女"
},{
name:"王武",
age:25,
gender:"中"
}]
let str = headers.map(th=>th.name).join(",")+"\n"//表头
str+=list.map(row=>{
return headers.map(th=>row[th.key]||'').join("\t,")
}).join("\n")
document.addEventListener("click",(e:MouseEvent)=>{
const t = e.target as HTMLElement
switch(t.dataset.export){
case "xls":
export2xls(str,"test");
break
case "cvs":
export2csv(str,"test");
break
}
})
to bundle your application