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

@alfonsobries/xlsx-laravel-spreadsheet-importer

v1.0.12

Published

Imports sheets from xlsx file to the database tables, and send artisan commands to track progress

Downloads

17

Readme

laravel-spreadsheet-importer

Based on @proscom/xlsx-to-database

CLI tool to import sheets from xlsx files into temporal database tables that are much easier to work with.

  • It optionally triggers PHP Laravel artisan commands to track the progress of the import into your Laravel app.
  • You can interact with those artisan commands by using the laravel package, it also allow you to easily interact with the temporal data: laravel-spreadsheet-importer
  • Compatible with multiple formats, see the compatible formated in the dependency (https://www.npmjs.com/package/xlsx#file-formats)
  • Once the temporal table is uploaded, you can play with the data, execute Eloquent & SQL queries, import the content into the final table, etc., and of course once you finish working with the data you can remove the temporal table.
  • Using node instead of PHP for reading and import spreadsheets is considerably faster, also, because you will work with a temporal database table, the data is much easier to work with and the operations are faster.
  • Compatible with PostgreSQL as MySQL

Uses pg-copy-streams for faster inserts in PostgreSql datatabases. Uses xlsx to parse xlsx files.

Installation:

npm install @alfonsobries/xlsx-laravel-spreadsheet-importer --save

Usage:

Create a .env file with the database settings (If the files exists in your laravel app this step is not neccesary)

DB_CONNECTION=pgsql # or mysql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=my_database
DB_USERNAME=admin
DB_PASSWORD=
$ ./node_modules/.bin/xlsx-laravel-spreadsheet-importer \
    -i input.xlsx \

Or for a laravel app

$ ./node_modules/.bin/xlsx-laravel-spreadsheet-importer \
    -i input.xlsx \
    --php /usr/bin/php \
    --artisan /home/myproject/path/artisan \
    --env testing
    --relatedId 1
    --relatedClass "App\Models\MyModel"

The laravel package automatically generates this command for you: laravel-spreadsheet-importer

$ xlsx-laravel-spreadsheet-importer --help
Options:
  --help               Show help                                       [boolean]
  --version            Show version number                             [boolean]
  --input, -i          Input xlsx file                       [string] [required]
  --sheets, -s         Only import specified sheets                      [array]
  --sheetsIndex, --si  Only import specified sheets index                [array]
  --prefix, -p         Prefix is prepended to the table name
                                                          [string] [default: ""]
  --tableNames, -n     Table names to use when storing the data (instead of the
                       sheet name)                         [array] [default: []]
  --batchSize, -b      Amount of rows per single insert query
                                                        [number] [default: 1000]
  --drop               Drops and recreates matched tables
                                                      [boolean] [default: false]
  --create, -c         Creates tables                 [boolean] [default: false]
  --id                 If set generates and ID column with the value
                                                        [string] [default: null]
  --relatedId          Name of the related ID where the data comes from (to send
                       to the artisan command)          [string] [default: null]
  --relatedClass       Name of the related Model Class where the data comes from
                       (to send to the artisan command) [string] [default: null]
  --columns            Extra column:value to add into the database
                                                           [array] [default: []]
  --formatted, -f      Read as formatted text by default
                                                      [boolean] [default: false]
  --artisan            Laravel php artisan path           [string] [default: ""]
  --php                php executable path             [string] [default: "php"]
  --env                enviroment to sent to the artisan command
                                                          [string] [default: ""]

Artisan command

If the --artisan option is set it will create a Laravel artisan command with the progress of the import that can be read in a Laravel app.

| Option | Possible values | Description | | --------- | ------------------------------------------------------------ | ------------------------------------------------------------ | | --relatedClass | Any value used a relatedClass param | Optional id that was sent as a param when running the script (useful to associate the data to a model for example) | | --relatedId | Any value used a relatedId param | Optional id that was sent as a param when running the script (useful to associate the data to a model for example) | | --type | started, readed, connected, total_rows, table_created, error, finished,processing | | | --data | Depends of the type of the progress, for total_rows the number of rows, for table_created the name of the table, for error the error message, for processing the total rows processed | Data related with the progress type | | --env | Laravel app enviroment | Optional env that was sent as a param when running the script (to run the artisan command in different enviroments) | | --pid | The current process id | The process id of the running script, useful for kill the process if neccesary |