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

excel-template-generator

v3.0.5

Published

A js excel template used in browser or nodejs environment.

Downloads

111

Readme

js-excel-template

Dependency Status devDependency Status Build Status: Windows Github CI npm version Downloads gzip size type-coverage

A js excel template used in browser or nodejs environment.

install

npm i js-excel-template

features

  • Generate Excel based on Excel template
  • (for nodejs)Read excel file as template
  • (for nodejs)Write to excel file
  • (for nodejs)To a Buffer for downloading
  • (for browser-side js)Take ArrayBuffer as template, coming from HTTP downloading, browser uploading or Websocket downloading
  • (for browser-side js)To a ArrayBuffer or Blob for HTTP uploading, browser-side downloading or Websocket uploading

example

template

// nodejs:
import JsExcelTemplate from "js-excel-template";
const excelTemplate = await JsExcelTemplate.fromFile("demo/test.xlsx");

// browser(module):
// import * as FileSaver from "file-saver";
// import JsExcelTemplate from "js-excel-template";
// const response = await fetch('./test.xlsx')
// const arrayBuffer = await response.arrayBuffer()
// const excelTemplate = await JsExcelTemplate.fromArrayBuffer(arrayBuffer)

// browser(script tag):
// <script src="file-saver/FileSaver.min.js"></script>
// <script src="exceljs/dist/exceljs.min.js"></script>
// <script src="js-excel-template/js-excel-template.min.js"></script>
// <script>
//   const response = await fetch('./test.xlsx')
//   const arrayBuffer = await response.arrayBuffer()
//   const excelTemplate = await JsExcelTemplate.fromArrayBuffer(arrayBuffer)

excelTemplate.set("name", "John");
excelTemplate.set("age", 123);
excelTemplate.set("now", new Date());
excelTemplate.set("isBoy", true);
excelTemplate.set('isGirl', {
  richText: [
    {
      text: 'false',
      font: {
        strike: true,
      },
    },
  ],
})

const students = [
  { name: "Tommy", age: 12 },
  { name: "Philips", age: 13 },
  { name: "Sara", age: 14 },
];

for (let i = 1; i <= 5; i++) {
  if (i <= students.length) {
    excelTemplate.set(`name${i}`, students[i - 1].name);
    excelTemplate.set(`age${i}`, students[i - 1].age);
  } else {
    excelTemplate.set(`name${i}`, "");
    excelTemplate.set(`age${i}`, "");
  }
}
excelTemplate.set("average", students.reduce((p, c) => p + c.age, 0) / students.length);

excelTemplate.set('fields', [{ name: 'Name' }, { name: 'Age' }], { duplicateCellIfArray: true })

excelTemplate.set("students", students);

// nodejs:
await excelTemplate.saveAs("spec/out.xlsx");

// browser(module):
// const blob = await excelTemplate.toBlob()
// FileSaver.saveAs(blob, "test.xlsx");

// browser(script tag):
//   const blob = await excelTemplate.toBlob()
//   FileSaver.saveAs(blob, "test.xlsx");
// </script>

out

change logs

// v3
const excelTemplate = await JsExcelTemplate.fromFile("demo/test.xlsx");
const excelTemplate = await JsExcelTemplate.fromArrayBuffer(arrayBuffer);
<script src="exceljs/dist/exceljs.min.js"></script>
await excelTemplate.saveAs("spec/out.xlsx");
const blob = await excelTemplate.toBlob()

// v2
const excelTemplate = JsExcelTemplate.fromFile("demo/test.xlsx");
const excelTemplate = JsExcelTemplate.fromArrayBuffer(arrayBuffer);
<script src="xlsx/dist/xlsx.full.min.js"></script>
excelTemplate.saveAs("spec/out.xlsx");
const blob = excelTemplate.toBlob()
// v2
import JsExcelTemplate from "js-excel-template/nodejs/nodejs";
import JsExcelTemplate from "js-excel-template/browser/browser";

// v1
import { JsExcelTemplate } from "js-excel-template/nodejs";
import { JsExcelTemplate } from "js-excel-template/browser";