2017 © Pedro Peláez
 

library xport

Import/Export library for PHP

image

myclabs/xport

Import/Export library for PHP

  • Tuesday, July 1, 2014
  • by mnapoli
  • Repository
  • 3 Watchers
  • 18 Stars
  • 395 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

Xport

Build Status Coverage Status Scrutinizer Quality Score, (*1)

Xport is an import/export library for PHP., (*2)

It is targeted to support the following formats:, (*3)

  • Excel (xlsx and xls)
  • OpenOffice (ods - to be implemented)
  • 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 and Twig to map your data (arrays, objects, …) onto the model., (*4)

Spreadsheet

Simple example

Simple mapping file (YAML file):, (*5)

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

    # Another sheet named "Contacts"
  - label: "Contacts"

    content:
    # Containing one table with 2 columns
      - type: VerticalTable
        columns:
          - "Name"
          - "Phone Number"
        lines:
          - foreach: "contacts as contact"
            do :
              - cells:
                - "{{ contact.name }}"
                - "{{ contact.phoneNumber }}"

Usage:, (*6)

$modelBuilder = new SpreadsheetModelBuilder();
$export = new PHPExcelExporter();

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

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

The table will be filled with each item in the array $contacts., (*7)

The path configuration is a PropertyAccess path, e.g. the contact.phoneNumber path can resolve to $contact->getPhoneNumber() or $contact->phoneNumber., (*8)

Dynamic example

You can use the foreach expression to generate dynamic content., (*9)

You can also use Twig templating language., (*10)

Here is an example:, (*11)

# Create one sheet per company
sheets:
  - foreach: companies as i => company
    do:
      - label: "{{ i + 1 }} - {{ company.name }}" # Twig expression, will result in (for example): "1 - My Company"
$modelBuilder = new SpreadsheetModelBuilder();
$export = new PHPExcelExporter();

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

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

Here is a more complete example:, (*12)

sheets:

    # Create one sheet per company
  - foreach: companies as company
    do:

      - label: "{{ company.name }}"
        content:
            # One content(VerticalTable) per product, each, followed by an empty line

          - foreach: company.products as product
            do:

              - type: VerticalTable
                label: product.label
                columns:
                  - "Product"
                  - "Price"
                  - "Salesman"
                # One line per sale, each, preceded by an empty line
                lines:
                  - foreach: product.getSalesList() as sale
                    do:
                      -
                      - cells:
                          - "{{ product.name }}"
                          - "{{ sale.price }}"
                          - "{{ sale.salesman.name }}"

              - type: EmptyLine

Functions

Functions can be used in Twig expressions, and are defined as such:, (*13)

$modelBuilder = new SpreadsheetModelBuilder();
$export = new PHPExcelExporter();

$modelBuilder->bindFunction('up', function($str) {
    return strtoupper($str);
});

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

File format

You can choose which file format to use through PHPExcel writers:, (*14)

// ...
$export->export($spreadsheet, 'myFile.xslx', new PHPExcel_Writer_Excel2007());

Writers available:, (*15)

  • Excel 2007 (.xlsx): PHPExcel_Writer_Excel2007
  • Excel classic (.xls): PHPExcel_Writer_Excel5
  • CSV (.csv): PHPExcel_Writer_CSV

The Versions

01/07 2014

dev-feature/import

dev-feature/import https://github.com/myclabs/Xport

Import/Export library for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

xml excel export pdf import

13/02 2014

dev-master

9999999-dev https://github.com/myclabs/Xport

Import/Export library for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

xml excel export pdf import

13/02 2014
11/10 2013
30/09 2013
10/06 2013

0.1.0

0.1.0.0 https://github.com/myclabs/Xport

Import/Export library for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

xml excel export pdf import