export-to-exceljs-util
v1.1.0
Published
使用exceljs导出excel文件
Downloads
43
Readme
export-to-exceljs-util
简介
export-to-exceljs-util 是一个基于 exceljs 的前端库,用于实现多表头的 Excel 文件导出功能。
安装指南
安装命令
您可以通过 npm 或 yarn 来安装export-to-exceljs-util。
使用 npm 安装:
npm i export-to-exceljs-util使用 yarn 安装:
yarn add export-to-exceljs-util代码示例
import ExcelExporter from "export-to-exceljs-util";
// 列数据
const columns = [
{
title: "姓名",
children: [
{
title: "姓",
key: "first_name",
},
{
title: "名",
key: "last_name",
},
],
},
{
title: "年龄",
key: "age",
},
{
title: "地址",
key: "address",
},
];
// 数据列表
const data = [
{
name: "张三",
age: 25,
address: "北京市",
},
];
// 文件名称
const fileName = "测试数据.xlsx";
// 其他信息(可选)
const otherInfo = '注释:这里是一些其他信息';
// 创建 Excel 导出实例
const excelExporter = new ExcelExporter(columns, data, fileName, otherInfo);
// 执行导出操作
excelExporter.exportToExcel();注意事项
- data 数组的每一项必须包含与 columns 数组中相同的 key。
- 当时数据量大于1w行时,工具类ExcelExporter参数属性必须是可被复制的,比如示例中的columns,data中的属性都是简单的数字、字符串、布尔值等,如使用vue3的ref声明的对象,需要使用toRaw()方法转换为普通对象,否则会报错。
- 此工具类未压缩代码,需要自定义样式的开发者可以自提代码进行修改。
