logo

typexlsx

Write *.xlsx files in a browser or Node.js

export Data Sheet to xlsx

import { saveAs } from 'file-saver';
import generateXlsx from 'typexlsx';

const sheet: Sheet = {
    name: 'TestFile',
    rows: [
        [
            {
                value: 'A',
                span: 2,
                border: { end: { color: '#000000', style: 'thick' } },
            },
            { value: 'B' },
            {
                value: 'C',
                font: { family: 'Times New Roman', color: '#00FF00' },
                fill: '#880077',
            },
        ],
        [{ value: 1 }, { value: 2 }, { value: 3 }],
        [{ value: 'test', span: 3, rowSpan: 2 }],
    ],
};

generateXlsx(TEST_FILE)
    .then((blob) => saveAs(blob, 'Workbook.xlsx'))
    .catch((err) => console.error(err));

export HTML Table to xlsx

table {
    border-collapse: collapse;
    width: 100%;
    text-align: center;
}
table > thead > tr > th {
    background-color: #c5d9f1;
}
.even {
    background-color: #d8e4bc;
}
.odd {
    background-color: #ebf1de;
}
table > tfoot > tr {
    background-color: #d99594;
}
table > thead > tr > th,
table > tbody > tr > td,
table > tfoot > tr > td {
    color: black;
    padding: 4px;
    border: 2px solid black;
}

import { saveAs } from 'file-saver';
import generateXlsx, { htmlTableToSheet } from 'typexlsx';

generateXlsx(htmlTableToSheet(document.getElementById('table')))
    .then((blob) => saveAs(blob, 'Workbook.xlsx'))
    .catch((err) => console.error(err));

Anlagen Nr. Wechselrichter Dachausrichtung Dachneigung Strings Module pro String Module pro WR kWp pro WR Kunde
3 Huawei SUN2000 60KTL-M0 90° 12° 2 18 210 67,200 kWp Max Mustermann
90° 12° 2 18
90° 12° 2 18
90° 12° 2 17
90° 12° 2 17
90° 12° 2 17
6 Huawei SUN2000 60KTL-M0 12° 2 16 172 66,666 kWp Max Mustermann
12° 2 14
12° 2 14
12° 2 14
12° 2 14
12° 2 14
Summe: 382 69,420 kWp