1.2.4 • Published 5 years ago

@soyzr/table-to-excel v1.2.4

Weekly downloads
-
License
ISC
Repository
github
Last release
5 years ago

table-to-excel

API

typescript interface

type IDataArray = Array<any[]>;

type ICB = (err: any, data?: any) => any;

interface IDataSource {
    title?: IDataArray;
    body: IDataArray;
}

interface ITableProp {
    filename?: string;
    dataSource?: IDataSource;
    table?: string | HTMLElement;
    callback?: ICB;
}

example

dataSource

const TableToExcel = require("@soyzr/table-to-excel");

new TableToExcel({
    filename: "table_to_excel_list",
    dataSource: {
        title: [["Message", null, null, "Other"], ["Name", "Sex", "Age", "Time"]],
        body: [["ZA", "male", 18, new Date()], ["LS", "male", 22, new Date()]]
    }
});

table

  1. HTMLElement
const TableToExcel = require("@soyzr/table-to-excel");

const table = document.querySelector("table");

const btn = document.querySelector("button");

btn.addEventListener(
    "click",
    function() {
        new TableToExcel({
            filename: "table_to_excel_list",
            table
        });
    },
    false
);
  1. string
const TableToExcel = require("@soyzr/table-to-excel");

const table = `
<table>
    <thead>
        <tr>
            <th>Name</th>
            <th>Sex</th>
            <th>Age</th>
            <th>Time</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>ZS</td>
            <td>male</td>
            <td>18</td>
            <td>2019103 0</td>
        </tr> 
    </tbody>
</table>
`;

new TableToExcel({
    filename: "table_to_excel_list",
    table
});