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

xlsx-to-csv

v2.0.0

Published

Ultra-fast XLSX to CSV converter

Downloads

328

Readme

The Fastest XLSX to CSV Converter. Rust powered.

This library provides an easy way to convert Excel files (.xlsx, .xls, .xlsm, etc.) to CSV format using custom options such as specifying a sheet, delimiter, datetime format, and destination. It uses a Rust-powered backend for efficient processing.

Installation

To use this library, install the required NPM package by running:

# Using npm
npm install xlsx-to-csv

# Using yarn
yarn add xlsx-to-csv

Make sure to have the binary executable for the conversion process set up as per your platform requirements.

Usage

convertFile(filePath: string, options: ConvertFileOptions = {}): string

Converts an Excel file to CSV format with customizable options.

Parameters:

  • filePath (string): Path to the Excel file you want to convert.

  • options (ConvertFileOptions, optional): An object containing various settings to customize the conversion process.

ConvertFileOptions

The options object allows you to configure the conversion with the following fields:

| Field | Type | Description | Default | |------------------|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------| | sheet | string | Sheet name to convert. If not provided, the first sheet will be used. | First sheet | | delimiter | string | Delimiter to use in the CSV file. You can choose between ;, ,, or any custom delimiter string. | ; | | dest | string | Destination file path. If set to 'return', it will return the CSV data as a string. If not specified, it will print to stdout. | stdout | | datetimeFormat | string | Format for parsing datetime values in the sheet. Follows the chrono format documentation. | %Y-%m-%d %H:%M:%S |

Example Usage

import {convertFile} from 'your-library-name';

// Convert an Excel file to CSV and save it to a specific path
convertFile('example.xlsx', {
    sheet: 'Sheet1',
    delimiter: ',',
    dest: 'output.csv',
    datetimeFormat: '%d-%m-%Y %H:%M'
});

// Convert an Excel file to CSV and return the result as a string
const csvData = convertFile('example.xlsx', {
    sheet: 'Sheet1',
    delimiter: ';',
    dest: 'return',
    datetimeFormat: '%Y-%m-%d'
});

console.log(csvData);

CLI Arguments Mapping

This library internally runs a binary command with the following mappings:

| Option | CLI Argument | |------------------|------------------------------| | filePath | --file <filePath> | | sheet | --sheet <sheet> | | delimiter | --delimiter <delimiter> | | dest | --dest <dest> | | datetimeFormat | --datetime-format <format> |

Additional Information

  • The library supports a variety of Excel formats (.xlsx, .xls, .xlsm, .xlsb).
  • For datetimeFormat, it uses the popular chrono crate for flexible and powerful date formatting options.

Credits

Contributing

  • Install Node.js and NPM on your system.
  • Clone the repository and install the dependencies using yarn install.
  • Install Rust and Cargo on your system.
  • Try running the project locally using cargo build.
  • Prepare for cross-compilation by installing the required targets.
    • Windows: https://gist.github.com/Mefistophell/9787e1b6d2d9441c16d2ac79d6a505e6
    • Linux: rustup target add x86_64-unknown-linux-gnu
    • MacOS M*: rustup target add aarch64-apple-darwin
    • MacOS Intel: rustup target add x86_64-apple-darwin
    • Update vim ~/.cargo/config.toml with the following:
       [target.x86_64-unknown-linux-gnu]
       linker = "x86_64-unknown-linux-gnu-gcc"
        
       [target.x86_64-pc-windows-gnu]
       linker = "x86_64-w64-mingw32-gcc"

License

This project is licensed under the MIT License.


Feel free to open an issue or contribute to the repository if you encounter any bugs or have feature suggestions!