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

@wayfu/simple-xlsx

v0.0.3

Published

Simple XLSX Reader and Writer

Downloads

6

Readme

logo logo

An easy Way to Read and Write XLSX file.

Simple version of by read-excel-file © Nikolay for reading XLSX file. Using FileSaver.js © Eli Grey to automatically download the output file.

NPM

npm i --save @wayfu/simple-xlsx

In your app.js import and initialized the module like normal.

import XLSX from "@wayfu/simple-xlsx";

Vanilla

If you wish to skip the modular build and NOT use npm you can use the vanilla build like so:

CDN

<script src="https://unpkg.com/@wayfu/simple-xlsx@latest/dist/index.min.js"></script>

How to use it:

Read File

From file input

<input type="file" id="input" />

<script>
    let input = document.querySelector("#input");
    
    // File.
    input.addEventListener('change', () => {
        XLSX.read(input.files[0]).then((rows) => {
            // `rows` is an array of rows
            // each row being an array of cells.
        });
    });
</script>

From Blob

fetch('https://example.com/spreadsheet.xlsx')
  .then(response => response.blob())
  .then(blob => XLSX.read(blob))
  .then((rows) => {
    // `rows` is an array of rows
    // each row being an array of cells.
  });

From ArrayBuffer

// ArrayBuffer.
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer
//
// Could be obtained from:
// * File
// * Blob
// * Base64 string
//
XLSX.read(arrayBuffer).then((rows) => {
  // `rows` is an array of rows
  // each row being an array of cells.
})

Using Async/Await function

async function readExcel(file){
    let sheetData = await XLSX.read(file);

    // `sheetData` is an array of rows
    // each row being an array of cells.
    // do something with `sheetData`.
}

readExcel(arrayBuffer);

Write File

Write XLSX function will automatically download it via Browser. By Using XLSX.write() you can write an excel file from your data. For example.

// The data it self can be 2 dimensional array data[row][column]

let data = [
    ['first-name', 'last-name'], // this is the first row
    ['John', 'Doe'] // this is the second row
];

// XLSX.write accept at least 2 parameter (can be 3).
// First parameter is the data it self
// Second parameter is the name of the file
// and Third parameter (optional) is the name of the sheet
XLSX.write(data, 'users');
// This output is create and downloading `users.xlsx` file

Options

XLSX.read() also accept option as second parameter. The option parameter is an object. Here is the default option value.

{
    sheet: 1,                   // sheet number/name (string|number)
    trim: false,                // Trim the value data or not (boolean)
    epoch1904: false,           // Is it epoch1904? (boolean)
    transformData: undefined,   // Function for transforming the data 
}
// Usage
XLSX.read(arrayBuffer, { sheet: 2 })
    .then((rows) => {
        // `rows` is an array of rows from sheet 2
        // each row being an array of cells.
    })

TypeScript

This library comes with TypeScript "typings". If you happen to find any bugs in those, create an issue.

License

Copyright © 2023 Wayfu under ISC License