1.6.80 • Published 23 days ago

xlsx2sql v1.6.80

Weekly downloads
2
License
ISC
Repository
-
Last release
23 days ago

README

Install

npm install xlsx2sql

Description

Transform an xlsx file into a list of sql insert statement.

  • Columns in excel file can be ignored

  • title line in excel file can be ignored

  • You can specify a custom name for the table used in the generated sql

  • You can specify a custom name for each field

  • You can specify a custom converter if needed for each field

  • Date can be converted to mysql format with our converter

  • You can add a custom value (useful if the excel doent contain all the necessary fields)

Exemple

See exemple files for details :

usage exemple :

var xlsx2sql = require('xlsx2sql')

xlsx2sql.xlsx2sql(`${__dirname}/test.xlsx`, {
    // the name if the table
    name: 'product',
    // the number of first lines to skip
    skip: 1,
    // the fields specifications
    fields: [
        // title is the name of the sql field. It will read the 0's column in excel file
        { index: 0, name: 'title' },
        // start is the name of the sql field. It will read the 1's column in excel file, and convert it using the special date converter
        { index: 1, name: 'start', convert: xlsx2sql.ExcelDateToJSDate },
        // you can also provide a custon function for convertions
        { index: 2, name: 'tva_id', convert: (v) => {
            if (v == '0.1') return 60;
            else if (v == '0.2') return 61;
            else if (v == '0.055') return 59;
            else if (v == '0') return 58;
            else throw new Error('Unknown tva '+v);
        }},
        { index: 3, name: 'tarifLibreTtc' },
        { index: 4, name: 'tarifLibreBoolean', convert: (v) => {
            if (v == 'ON') return 1;
            else return 0;
        }},
        { index: 5, name: 'compta' },
        { name: 'createdAt', value: 'now()' },
        { name: 'updatedAt', value: 'now()' },
    ]
}, (err, sql) => {

    // generated sql is :
    // insert into `product` (`title`,`start`,`tva_id`,`tarifLibreTtc`,`tarifLibreBoolean`,`compta`,`createdAt`,`updatedAt`) values
    // ('Privatisation complète du château avec hébergement','43466','60','0','1','74501652',now(),now()),
    // ('Hébergement en chambre single','43466','60','0','1','74501652',now(),now()),
    // ('Petit déjeuner','43466','60','0','1','74501652',now(),now()) ;

})
1.6.80

23 days ago

1.6.79

1 month ago

1.6.78

1 month ago

1.6.76

3 months ago

1.6.57

12 months ago

1.6.59

12 months ago

1.6.58

12 months ago

1.6.60

11 months ago

1.6.62

11 months ago

1.6.61

11 months ago

1.6.64

11 months ago

1.6.63

11 months ago

1.6.66

11 months ago

1.6.65

11 months ago

1.6.68

11 months ago

1.6.67

11 months ago

1.6.69

11 months ago

1.6.71

11 months ago

1.6.70

11 months ago

1.6.73

10 months ago

1.6.72

10 months ago

1.6.75

7 months ago

1.6.74

8 months ago

1.6.4

1 year ago

1.6.3

1 year ago

1.6.2

1 year ago

1.6.1

1 year ago

1.6.0

1 year ago

1.4.1

1 year ago

1.4.0

1 year ago

1.6.40

1 year ago

1.6.42

1 year ago

1.6.41

1 year ago

1.6.44

1 year ago

1.6.43

1 year ago

1.6.46

1 year ago

1.6.45

1 year ago

1.6.48

12 months ago

1.6.47

12 months ago

1.6.49

12 months ago

1.6.51

12 months ago

1.6.50

12 months ago

1.6.53

12 months ago

1.6.52

12 months ago

1.6.55

12 months ago

1.6.11

1 year ago

1.6.54

12 months ago

1.6.10

1 year ago

1.6.13

1 year ago

1.6.56

12 months ago

1.6.12

1 year ago

1.6.15

1 year ago

1.6.14

1 year ago

1.6.17

1 year ago

1.6.16

1 year ago

1.6.19

1 year ago

1.6.18

1 year ago

1.5.0

1 year ago

1.6.20

1 year ago

1.6.22

1 year ago

1.6.21

1 year ago

1.6.24

1 year ago

1.6.23

1 year ago

1.6.26

1 year ago

1.6.25

1 year ago

1.6.28

1 year ago

1.6.27

1 year ago

1.6.29

1 year ago

1.6.31

1 year ago

1.6.30

1 year ago

1.6.9

1 year ago

1.6.33

1 year ago

1.6.8

1 year ago

1.6.32

1 year ago

1.6.7

1 year ago

1.6.35

1 year ago

1.6.6

1 year ago

1.6.34

1 year ago

1.6.5

1 year ago

1.6.37

1 year ago

1.6.36

1 year ago

1.6.39

1 year ago

1.6.38

1 year ago

1.2.0

1 year ago

1.1.1

1 year ago

1.0.2

1 year ago

1.1.0

1 year ago

1.3.2

1 year ago

1.3.1

1 year ago

1.3.0

1 year ago

1.1.2

1 year ago

1.0.3

1 year ago

1.0.1

4 years ago

1.0.0

5 years ago