1.6.80 • Published 1 year ago

xlsx2sql v1.6.80

Weekly downloads
2
License
ISC
Repository
-
Last release
1 year 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

1 year ago

1.6.79

1 year ago

1.6.78

1 year ago

1.6.76

1 year ago

1.6.57

2 years ago

1.6.59

2 years ago

1.6.58

2 years ago

1.6.60

2 years ago

1.6.62

2 years ago

1.6.61

2 years ago

1.6.64

2 years ago

1.6.63

2 years ago

1.6.66

2 years ago

1.6.65

2 years ago

1.6.68

2 years ago

1.6.67

2 years ago

1.6.69

2 years ago

1.6.71

2 years ago

1.6.70

2 years ago

1.6.73

2 years ago

1.6.72

2 years ago

1.6.75

2 years ago

1.6.74

2 years ago

1.6.4

2 years ago

1.6.3

2 years ago

1.6.2

2 years ago

1.6.1

2 years ago

1.6.0

2 years ago

1.4.1

2 years ago

1.4.0

2 years ago

1.6.40

2 years ago

1.6.42

2 years ago

1.6.41

2 years ago

1.6.44

2 years ago

1.6.43

2 years ago

1.6.46

2 years ago

1.6.45

2 years ago

1.6.48

2 years ago

1.6.47

2 years ago

1.6.49

2 years ago

1.6.51

2 years ago

1.6.50

2 years ago

1.6.53

2 years ago

1.6.52

2 years ago

1.6.55

2 years ago

1.6.11

2 years ago

1.6.54

2 years ago

1.6.10

2 years ago

1.6.13

2 years ago

1.6.56

2 years ago

1.6.12

2 years ago

1.6.15

2 years ago

1.6.14

2 years ago

1.6.17

2 years ago

1.6.16

2 years ago

1.6.19

2 years ago

1.6.18

2 years ago

1.5.0

2 years ago

1.6.20

2 years ago

1.6.22

2 years ago

1.6.21

2 years ago

1.6.24

2 years ago

1.6.23

2 years ago

1.6.26

2 years ago

1.6.25

2 years ago

1.6.28

2 years ago

1.6.27

2 years ago

1.6.29

2 years ago

1.6.31

2 years ago

1.6.30

2 years ago

1.6.9

2 years ago

1.6.33

2 years ago

1.6.8

2 years ago

1.6.32

2 years ago

1.6.7

2 years ago

1.6.35

2 years ago

1.6.6

2 years ago

1.6.34

2 years ago

1.6.5

2 years ago

1.6.37

2 years ago

1.6.36

2 years ago

1.6.39

2 years ago

1.6.38

2 years ago

1.2.0

2 years ago

1.1.1

2 years ago

1.0.2

3 years ago

1.1.0

2 years ago

1.3.2

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.1.2

2 years ago

1.0.3

3 years ago

1.0.1

5 years ago

1.0.0

6 years ago