PHPackages                             ahmadpriatama/xls-woles - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. ahmadpriatama/xls-woles

ActiveLibrary[File &amp; Storage](/categories/file-storage)

ahmadpriatama/xls-woles
=======================

v0.1.1(9y ago)21.5k2PHP

Since Aug 19Pushed 9y ago1 watchersCompare

[ Source](https://github.com/ahmadpriatama/xls-woles)[ Packagist](https://packagist.org/packages/ahmadpriatama/xls-woles)[ RSS](/packages/ahmadpriatama-xls-woles/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (2)Versions (5)Used By (0)

xls-woles [![Build Status](https://camo.githubusercontent.com/ab96a0a0d4576add47b9fdd149f75aef4d66a3aa547ab3d5ad7f36b9ae577147/68747470733a2f2f7472617669732d63692e6f72672f61686d61647072696174616d612f786c732d776f6c65732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/ahmadpriatama/xls-woles)
==============================================================================================================================================================================================================================================================================================================

[](#xls-woles-)

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

### Install

[](#install)

Either run

```
$ php composer.phar require ahmadpriatama/xls-woles "*"

```

or add

```
"ahmadpriatama/xls-woles": "*"

```

to the `require` section of your `composer.json` file.

Demo
----

[](#demo)

see folder `demo`

Usage Example
-------------

[](#usage-example)

We have a list of children book in `Book1.xlsx` as shown below

[![alt tag](https://raw.githubusercontent.com/ahmadpriatama/xls-woles/master/demo/Book1.png)](https://raw.githubusercontent.com/ahmadpriatama/xls-woles/master/demo/Book1.png)

And your supervisor want clean data to be imported with specs:

1. Book name must stored in lower case string
2. Must split author name into first name and last name
3. ISBN must stored in format XXX-X-XX-XXXXXX-X
4. Language must stored in constant value ex: `Book::LANG_EN = 1` or `Book::LANG_NON_EN = 2`

and this is your script

```
$config = json_decode(file_get_contents($fileConfig), true);
$data = \XLSWoles\Reader::load($fileInput)
    ->setSheetName('Sheet1')
    ->setColumnConfig($config['columns'])
    ->setDataRange('a2:e6')
    ->fetch();

```

column-config.json:

```
{
  "columns" : {
    "book-name": {
      "filters": [
        "string-lowercase"
      ]
    },
    "author-name": {
      "filters":[
        "SplitNameFilter"
      ]
    },
    "publisher": {},
    "isbn": {
      "filters": [
        "regex||-||",
        "regex||(\\d{3})(\\d{1})(\\d{2})(\\d{6})(\\d{1})||$1-$2-$3-$4-$5"
      ]
    },
    "language": {
      "filters": [
        "string-lowercase",
        "regex||english||1"
      ]
    }
  }
}

```

you see that `author-name` field has `SplitNameFilter` which is a custom filter which source code as shown below:

```
