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

extend-excel

v0.0.6

Published

A export and inport excel funciton.

Downloads

12

Readme

Intro

This plugin package simplifies the process of importing and exporting Excel files, and it is built upon the file-saver and xlsx library.

Language

Extend-Excel

Import Excel

1)If you need to convert all data from an Excel file to JSON, the import_excel function is here to assist you.

test excel data:

Alt text

const { importExcel } = extendExcel

<!-- read file -->
const fileBuffer = fs.readFileSync(path.resolve(__dirname, './__mocks__/test.xlsx'))
const blob = new Blob([fileBuffer], { type : 'application/xlsx'});
const excelFile = new File([blob], 'test');

<!-- excel to json -->
const result = await importExcel(excelFile);
console.log(result)

2)If you want to convert the data from the first sheet of an Excel file to JSON, you can utilize the optional parameters to achieve this.

const { onlyFirst, XLSXReadOptions } = options

const result = await importExcel(excelFile, { onlyFirst: true })

3)If you want to convert the data from the first sheet of an Excel file to JSON, and mapping excel header name, you can utilize the optional parameters to achieve this.

const { onlyFirst, keyMapping, XLSXReadOptions } = options

const result = await importExcel(excelFile, {
  keyMapping: {
    测试1: 'test1',
    测试2: 'test2',
    测试3: 'test3',
    测试sheet1: 'testsheet1',
    测试sheet2: 'testsheet2',
    测试sheet3: 'testsheet3'
  }
})

result:

{
  name: 'test',
  data: [
    { 'test1': 1, 'test2': 2, 'test3': 3 },
    { 'testsheet1': 1, 'testsheet2': 2, 'testsheet3': 3 }
  ]
}

4)If you need additional options, you can pass the XLSXReadOptions parameter, which is compatible with xlsx options.

Export Excel

1)If you want to download an Excel file generated from JSON data, the export_excel function can assist you.

const { exportExcel } = extend-excel

<!-- json to excel -->
const headers = {
    'test': '测试1',
    'test2': '测试2',
    'test3': '测试3',
    'testsheet1': '测试sheet1',
    'testsheet2': '测试sheet2',
    'testsheet3': '测试sheet3',
  }

const sourceData = [
    { 'test': 1, 'test2': 2, 'test3': 3 },
    { 'testsheet1': 1, 'testsheet2': 2, 'testsheet3': 3 }
  ]

const options = {}

const result = await exportExcel(headers, sourceData, options)

1)If you want to custom file name and download an Excel file generated from JSON data, the export_excel function can assist you.

const { exportExcel } = extend-excel

<!-- json to excel -->
const headers = {
    'test': '测试1',
    'test2': '测试2',
    'test3': '测试3',
    'testsheet1': '测试sheet1',
    'testsheet2': '测试sheet2',
    'testsheet3': '测试sheet3',
  }

const sourceData = [
    { 'test': 1, 'test2': 2, 'test3': 3 },
    { 'testsheet1': 1, 'testsheet2': 2, 'testsheet3': 3 }
  ]

const options = { filename: 'test-export' }

const result = await exportExcel(headers, sourceData, options)

3)If you want to customize the properties of the downloaded file, you can do so by passing the options parameter.

const { fileName, sheetName, XLSXOption } = options

| Attribute name | info | | -------------- | --------------------------------------------- | | fileName | Customize the downloaded file's name. | | sheetName | Customize the downloaded file's sheetNmae. | | XLSXOption | Adjust the options for the FileSaver library. |

Installation


# Basic Node.JS installation
npm install extend-excel --save

Typescript Support

export interface DynamicObject {
  [key: string]: any
}

export interface ExportExcelOptions {
  fileName: string,
  sheetName: string,
  XLSXOption: WritingOptions
}

export interface ImportExcelOptions {
  onlyFirst: Boolean, // only first sheet
  XLSXReadOptions: ParsingOptions
}