<commit_before># Xport

Xport is an import/export library for PHP.

It is targeted to support the following formats:

- Excel/OpenOffice
- PDF (to be implemented)
- XML (to be implemented)

It provides an object model for different formats (spreadsheet, document, XML…) and a language based on YAML to map your data (arrays, objects, …) onto the model.

## Spreadsheet

### Simple example

Simple mapping file (YAML file):

```yaml
sheets:
    # An empty sheet named "Home"
  - label: Home

    # Another sheet named "Contacts"
  - label: Contacts

    tables:
        # Containing one table with 2 columns
      - lines:
          foreach: contacts as contact
        columns:
          name:
            label: Name
            path: contact.name
          phoneNumber:
            label: Phone number
            path: contact.phoneNumber
```

Usage:

```php
$modelBuilder = new SpreadsheetModelBuilder();
$export = new SpreadsheetExporter();

$modelBuilder->bind('contacts', $contacts);

$export->export($modelBuilder->build('mapping.yml'), 'myFile.xslx');
```

The table will be filled with each item in the array `$contacts`.

The `path` configuration is a [PropertyAccess](http://symfony.com/doc/master/components/property_access/index.html) path, e.g. the `contact.phoneNumber` path can resolve to `$contact->getPhoneNumber()` or `$contact->phoneNumber`.

### Dynamic example

You can use the `foreach` expression to generate dynamic content.

Here is an example:

```yaml
# Create one sheet per company
sheets:
  - foreach: companies as company
    label: company.name
```

```php
$modelBuilder = new SpreadsheetModelBuilder();
$export = new SpreadsheetExporter();

$modelBuilder->bind('companies', $companies);

$export->export($modelBuilder->build('mapping.yml'), 'myFile.xslx');
```

Here is a more complete example:

```yaml
sheets:
    # Create one sheet per company
  - foreach: companies as company<commit_msg>Support for keys in foreach<commit_after># Xport

Xport is an import/export library for PHP.

It is targeted to support the following formats:

- Excel/OpenOffice
- PDF (to be implemented)
- XML (to be implemented)

It provides an object model for different formats (spreadsheet, document, XML…) and a language based on YAML to map your data (arrays, objects, …) onto the model.

## Spreadsheet

### Simple example

Simple mapping file (YAML file):

```yaml
sheets:
    # An empty sheet named "Home"
  - label: Home

    # Another sheet named "Contacts"
  - label: Contacts

    tables:
        # Containing one table with 2 columns
      - lines:
          foreach: contacts as contact
        columns:
          name:
            label: Name
            path: contact.name
          phoneNumber:
            label: Phone number
            path: contact.phoneNumber
```

Usage:

```php
$modelBuilder = new SpreadsheetModelBuilder();
$export = new SpreadsheetExporter();

$modelBuilder->bind('contacts', $contacts);

$export->export($modelBuilder->build('mapping.yml'), 'myFile.xslx');
```

The table will be filled with each item in the array `$contacts`.

The `path` configuration is a [PropertyAccess](http://symfony.com/doc/master/components/property_access/index.html) path, e.g. the `contact.phoneNumber` path can resolve to `$contact->getPhoneNumber()` or `$contact->phoneNumber`.

### Dynamic example

You can use the `foreach` expression to generate dynamic content.

You can also use Twig templating language.

Here is an example:

```yaml
# Create one sheet per company
sheets:
  - foreach: companies as i => company
    label: "{{ i + 1 }} - {{ company.name }}" # Twig expression, will result in (for example): "1 - Company Name"
```

```php
$modelBuilder = new SpreadsheetModelBuilder();
$export = new SpreadsheetExporter();

$modelBuilder->bind('companies', $companies);

$export->export($modelBuilder->build('mapping.yml'), 'myFile.xslx');
```

Here is a more complete example:

```yaml
sheets:
    # Create one sheet per company
  - foreach: companies as company
{'fraction_non_alphanumeric': 0.11560549313358302, 'fraction_numerical': 0.0009987515605493133, 'mean_word_length': 3.6045977011494252, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1480307', 'n_tokens_mistral': 1186, 'n_tokens_neox': 1123, 'n_words': 419}