npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@pagodas/excel-write-stream

v0.0.6

Published

Create excel rows write stream.

Downloads

16

Readme

excel-write-stream

Create excel rows write stream.

It can create an duplex stream that you can write values row by row and read xlsx output binaries..

Install

$ npm i @pagodas/excel-write-stream --save

Usage

import {createExcelWriterDuplex, ExcelWriterCellInput} from '@pagodas/excel-write-stream';
import fs = require('fs');
import path = require('path');
import combine = require('multipipe');
import stream = require('readable-stream');

    // an readstream that have 100 rows.
    class TestRowsStream extends stream.Readable {
      private i = 0;

      constructor() {
        super({objectMode: true});
      }

      _read() {
        if (this.i > 100) {
          this.push(null);
        } else {
          this.push([ // row can be array of literal value.
            `first value${this.i}`,// string
            this.i,//number
            `third value${this.i}`,
          ]);
          this.i++;
        }
      }
    }

    const excelDuplex = createExcelWriterDuplex({
      columns: [// columns can be string[].
        'first row',
        'second row',
        'third',
      ],
    });
    // create an file write stream.
    const outFile = fs.createWriteStream(path.join(__dirname, './easy_data.xlsx'));

    // pipe the row read stream to excelDuplex, pipe the excelDuplex to file write stream.
    combine(new TestRowsStream(), excelDuplex, outFile, done);

A demo that support more features.

import {createExcelWriterDuplex, ExcelWriterCellInput} from '@pagodas/excel-write-stream';
import fs = require('fs');
import path = require('path');
import combine = require('multipipe');
import stream = require('readable-stream');
class TestRowsStream extends stream.Readable {
      private i = 0;

      constructor() {
        super({objectMode: true});
      }

      _read() {
        if (this.i > 100) {
          this.push(null);
        } else {
          this.push([
            {value: `${this.i}+aa`},
            {value: 'b'},
            {
              value: 1000, // cell value
              numberFormat: '#,##0.00_ ', //optional. numberFormat for number value show.
              background: '00FF00',// optional. set the background of cell.
              symbol: ['3Flags', this.i % 3],//optional.add icon to the cell,iconSet from excel condition format,
              // it's an array first value is iconSet type(example values:‘3Arrows’, ‘3ArrowsGray’, ‘3Flags’, ‘3TrafficLights1’, ‘3TrafficLights2’, ‘3Signs’, ‘3Symbols’, ‘3Symbols2’, ‘4Arrows’, ‘4ArrowsGray’, ‘4RedToBlack’, ‘4Rating’, ‘4TrafficLights’, ‘5Arrows’, ‘5ArrowsGray’, ‘5Rating’, ‘5Quarters’)
              // second value is the index in the iconSet ,first one is index:0.
              // mention that ,if the value is a string,then it will set it to 0,and add an numberFormat for the string display.
              customFun: (cell) => {// optional. an function that callback the cellObj,so that we can custom cell style. It's cell from the [exceljs].
                cell.fill = { // [exceljs](https://www.npmjs.com/package/exceljs#styles)
                  type: 'pattern',
                  pattern: 'solid',
                  fgColor: {argb: `FFFF0000`},
                }
              }
            }] as ExcelWriterCellInput[]);
          this.i++;
        }
      }
    }

    const excelDuplex = createExcelWriterDuplex({
      columns: [ // defined the table headers.
        {
          header: 'aa',
        },
        {
          header: 'Bb',
        },
        {
          header: 'cc',// header name.
          width: 80,// optional, column width.
          style: {alignment: {vertical: 'middle', horizontal: 'left'}},//optional,column styles
        },
      ],
      color2CrossLine: 'F5F5F5',// optional.cross line coloring.
      borderColor: '282828', // optional. border color,an rgb hex value.
      fixHeader: false,// optional.fix the header on top.default true ,we can close it by this option.
      rowsPerPage: 10,// optional.excel sheet have an row limit 1,048,576,so we must limit row count per page.default 100,000,we can change it by this option.
      sheetNameFun: (i) => `aa${i}`,// optional.the sheet name default create by function (i: number) => `My Sheet${i}`,we can replace by this option.
    });
    const outFile = fs.createWriteStream(path.join(__dirname, './a.xlsx'));
    combine(new TestRowsStream(), excelDuplex, outFile, done);

Questions & Suggestions

Please open an issue here.

License

MIT