zoukankan      html  css  js  c++  java
  • 2. node xlsx的使用

    1. 使用xlsx模块

    const xlsx = require('xlsx');
    
    //excel
        async exportexcel() {
            let arrayData = [
                ['姓名', '电话', '税率', '单价', '数量', '含税金额', '不含税金额', '税额', '付款状态', '付款方式', '创建时间', '上传更新时间'],
                ['小毛', '15888884444', '7%', '1000', '10', '10700', '10000', '700', '已付', '刷卡', '2019-08-07 10:51:17', '2019-08-12 18:03:20'],
                ['二毛', '158888833333', '10%', '10', '10', '110', '100', '10', '已付', '支付宝', '2019-08-07 10:51:47', '2019-08-12 18:03:20'],
                ['大毛', '15888882222', '10%', '10', '100', '11000', '10000', '1000', '已付', '现金', '2019-08-07 10:51:17', '2019-08-12 18:03:20'],
                ['小毛', '15888884444', '7%', '1000', '10', '10700', '10000', '700', '已付', '刷卡', '2019-08-07 10:51:17', '2019-08-12 18:03:20'],
            ];
    
            // 将数据转成workSheet
            let arrayWorkSheet = xlsx.utils.aoa_to_sheet(arrayData);
            // let jsonWorkSheet = xlsx.utils.json_to_sheet(jsonData);
    
            // 构造workBook
            let workBook = {
                SheetNames: ['arrayWorkSheet'],
                Sheets: {
                    'arrayWorkSheet': arrayWorkSheet
                },
            };
            let worksheet = workBook.Sheets['arrayWorkSheet'];
         // 尺寸 worksheet[
    '!rows'] = [{ hpx: 30 }]; worksheet['!cols'] = [{ wpx: 80, align: 'center' }, { wpx: 100 }, { wpx: 80 }, { wpx: 80 }, { wpx: 80 }, { wpx: 80 }, { wpx: 80 }, { wpx: 80 }, { wpx: 80 }, { wpx: 80 }, { wpx: 150 }, { wpx: 150 }, ]; // 将workBook写入文件 // xlsx.writeFile(workBook, path.resolve(__dirname, "../public/aa.xlsx")); xlsx.writeFile(workBook, "./excel/aa.xlsx"); return arrayWorkSheet }

     
  • 相关阅读:
    sqlserver sql优化案例及思路
    mysql执行计划常用说明
    MYSQL 的rownum
    innodb crash
    spring-mybatis源码追踪
    mylyn提交到JIRA的日期格式错误
    [google面试CTCI] 2-1.移除链表中重复元素
    [google面试CTCI] 2-0.链表的创建
    [google面试CTCI] 1-8.判断子字符串
    [google面试CTCI] 1-7.将矩阵中特定行、列置0
  • 原文地址:https://www.cnblogs.com/wangrui38/p/11346928.html
Copyright © 2011-2022 走看看