Giter Site home page Giter Site logo

alfonsobries / xlsx-laravel-spreadsheet-importer Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 2.0 37 KB

Imports xslx files using node js in temporal tables and inform laravel application about the progress

License: MIT License

TypeScript 83.27% JavaScript 16.73%
xlsx postgresql

xlsx-laravel-spreadsheet-importer's Introduction

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

xlsx-laravel-spreadsheet-importer's People

Contributors

alfonsobries avatar dependabot[bot] avatar

Stargazers

 avatar Oscar Arzola avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.