# valid-xlsx

> validate columns in an xlsx worksheet

Latest version **0.0.5** (published 2014-09-29) · BSD-2-Clause license · 0 weekly downloads

## Install

```sh
npm install valid-xlsx
pnpm add valid-xlsx
yarn add valid-xlsx
bun add valid-xlsx
```

Provides the command `validate-xlsx`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.5 |
| Published | 2014-09-29 |
| First published | 2014-09-26 |
| Weekly downloads | 0 |
| License | BSD-2-Clause |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | joyrexus |
| Maintainers | joyrexus |
| Keywords | xlsx, parse, validate |

## Links

- npm: https://www.npmjs.com/package/valid-xlsx
- Repository: https://github.com/joyrexus/valid-xlsx
- Issues: https://github.com/joyrexus/valid-xlsx/issues
- npm.io page: https://npm.io/package/valid-xlsx

## Dependencies (3)

- [minimist](https://npm.io/package/minimist.md) ~1.1.0
- [parse-xlsx](https://npm.io/package/parse-xlsx.md) 0.0.6
- [valid-records](https://npm.io/package/valid-records.md) 0.0.2

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 0.0.5 (latest) — 2014-09-29
- 0.0.4 — 2014-09-29
- 0.0.3 — 2014-09-29
- 0.0.1 — 2014-09-26

## README

# valid-xlsx

A simple module and CLI for validation reporting on specified columns within an excel worksheet.

For the CLI, you pass in a file containing your column constraint functions:

    validate-xlsx --sheet=SheetName                      \
                  --constraints=your.column.constraints.js file.xlsx


## Usage

    npm install -g valid-xlsx
    npm run test
    npm run demo
    npm run cli-demo


## Example

Using the following sample file (`sample.xlsx`) ...

![sample file](sample.png)


#### CLI

    validate-xlsx --sheet=Transcript \
                  --constraints=sample.constraints.js sample.xlsx

Output ...

    4 invalid values

    REC 2:
      LRB = `L+ ` is an invalid value
    REC 3:
      XYZ = `q` is an invalid value
    REC 4:
      LRB = `L+R+X` is an invalid value
      XYZ = `b` is an invalid value


#### Module

You'll typically require a file containing a constraints object:

```javascript
var validate = require('valid-xlsx');
var constraints = require('sample.constraints');

var file = 'sample.xlsx',
    sheet = 'Transcript'

var results = validate(file, sheet, constraints);

console.log(results.report);
```

This should yield the following results:

```javascript
{ errors: 4,
  invalid: 
   { '2': [ 'LRB = `L+ ` is an invalid value' ],
     '3': [ 'XYZ = `q` is an invalid value' ],
     '4': 
      [ 'LRB = `L+R+X` is an invalid value',
        'XYZ = `b` is an invalid value' ] } }
```

The constraints object should contain functions to check the validity of column
values.  The key of each constraint function should reflect the name of the column values it validates.

In the example below, we define the constraints object inline.  It contains one
column constraint function, viz., a simple constraint on valid values for the `XYZ`
column:

```javascript
var validate = require('valid-xlsx');

var file = 'sample.xlsx',
    sheet = 'Transcript',
    constraints = {
        XYZ: function(v) {
            if (v) {
                if (!/^[xyz]$/.test(v)) {
                    return { XYZ: v + ' is not a valid value!' };
                }
            }
        }
    };

var results = validate(file, sheet, constraints);
console.log(results.report);
```

This produces the following results:

```javascript
{
  errors: 2,
  invalid: {
    '3': [ { XYZ: "q is not a valid value!" } ],
    '4': [ { XYZ: "b is not a valid value!" } ]
  }
}
```

See [`demo.js`](demo.js) for a slight elaboration of this example.


## See Also

* [`parse-xlsx`](https://github.com/joyrexus/parse-xlsx) - parse excel worksheets 
  with column headers
* [`valid-records`](https://github.com/joyrexus/valid-records) - validate
  specified fields within a set of records (ndjson)

---
_Source: https://npm.io/package/valid-xlsx · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
