Skip to content

Commit

Permalink
Added sxi (xlsx-import-cli) examples (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
Siemienik authored Jan 4, 2021
1 parent 5d1fb0f commit 97d5bfb
Show file tree
Hide file tree
Showing 12 changed files with 816 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/xlsx-import-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ sxi config.js invoice.xlsx | sxr template.xlsx > refreshed-invoice.xlsx

```

[Run prepared examples! :rocket:](../../samples/xlsx-import-cli)

## Command body

`sxi [options] <config.js> [input.xlsx]`
Expand Down
1 change: 1 addition & 0 deletions packages/xlsx-import/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ Example integrations with `xlsx-import` are placed in [samples](../../samples) d

* [NodeJS sample](../../samples/xlsx-import%2Bnodejs) of **importing an invoice** - it is pure JS example which runs on nodejs.
* [NodeJS + TS sample](../../samples/xlsx-import%2Bnodejs%2Bts) of **importing an invoice** - it is Typescript example that can be transpiled down to pure JS or run directly with ts-node.
* [**:star: Command line of xlsx-import**](../../samples/xlsx-import-cli) examples with prepared scripts based on cli version of xlsx-import.

### Backend

Expand Down
1 change: 1 addition & 0 deletions samples/xlsx-import-cli/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./node_modules
32 changes: 32 additions & 0 deletions samples/xlsx-import-cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Hello

This is an example how to use `xlsx-import-cli (sxi)` .

**LIB Version:** `0.0.1-alpha1`

## Scripts

* `npm run example:seller` same as `node_modules/.bin/sxi configs/seller.js invoice.xlsx` - imports seller data from invoice.xlsx.
* `npm run example:buyer` same as `node_modules/.bin/sxi configs/buyer.js invoice.xlsx` - imports buyer data from invoice.xlsx.
* `npm run example:items` same as `node_modules/.bin/sxi configs/items.js invoice.xlsx` - imports items data from invoice.xlsx.
* `npm run example:misc` same as `node_modules/.bin/sxi configs/misc.js invoice.xlsx` - imports misc data from invoice.xlsx.

* `npm run example:all` runs all above at once.

## What happened

1. Read spreadsheet file [Invoice.xlsx](invoice.xlsx)
2. Following config import requested data
3. Map and return data.

## What is worth to see here

1. Study importer configs: [`./configs/*.js`](configs/)
2. Scripts section in [`package.json`](./package.json)

## What later

1. Study documentation: [docs](./../../README.md)
2. Start using **XToolset** in your project
3. Ask a lot, report bugs and request for help: <https://github.com/Siemienik/xtoolset/issues>
4. [Sponsor `xtoolset` project](https://github.com/sponsors/Siemienik)
3 changes: 3 additions & 0 deletions samples/xlsx-import-cli/configs/buyer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const cfg = require('./invoiceConfig');

module.exports = cfg.getInvoiceConfig().buyer;
45 changes: 45 additions & 0 deletions samples/xlsx-import-cli/configs/invoiceConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const getInvoiceConfig = () => ({
seller: {
worksheet: 'Invoice',
type: 'object',
fields: [
{ row: 2, col: 1, key: 'name' },
{ row: 4, col: 2, key: 'taxIdNumber' },
{ row: 3, col: 1, key: 'address' },
{ row: 9, col: 4, key: 'accountNo' },
],
},

buyer: {
worksheet: 'Invoice',
type: 'object',
fields: [
{ row: 2, col: 5, key: 'name' },
{ row: 4, col: 6, key: 'taxIdNumber' },
{ row: 3, col: 5, key: 'address' },
],
},

misc: {
worksheet: 'Invoice',
type: 'object',
fields: [
{ row: 6, col: 5, key: 'date', mapper: v => new Date(v) }, //todo mapper
{ row: 7, col: 5, key: 'dueDate', mapper: v => new Date(v) }, //todo mapper
],
},

items: {
worksheet: 'Invoice',
type: 'list',
rowOffset: 13,
columns: [
{ index: 2, key: 'item' },
{ index: 4, key: 'unitPrice', mapper: v => Number(v) },
{ index: 5, key: 'quantity', mapper: v => Number(v) },
{ index: 6, key: 'price', mapper: v => Number(v) },
],
},
});

module.exports = { getInvoiceConfig };
3 changes: 3 additions & 0 deletions samples/xlsx-import-cli/configs/items.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const cfg = require('./invoiceConfig');

module.exports = cfg.getInvoiceConfig().items;
3 changes: 3 additions & 0 deletions samples/xlsx-import-cli/configs/misc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const cfg = require('./invoiceConfig');

module.exports = cfg.getInvoiceConfig().misc;
3 changes: 3 additions & 0 deletions samples/xlsx-import-cli/configs/seller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const cfg = require('./invoiceConfig');

module.exports = cfg.getInvoiceConfig().seller;
Binary file added samples/xlsx-import-cli/invoice.xlsx
Binary file not shown.
Loading

0 comments on commit 97d5bfb

Please sign in to comment.