2017 © Pedro Peláez
 

yii2-extension yii2-importexport

Extension for the Yii2 framework for importing and exporting data

image

boundstate/yii2-importexport

Extension for the Yii2 framework for importing and exporting data

  • Friday, August 12, 2016
  • by mikejpeters
  • Repository
  • 2 Watchers
  • 1 Stars
  • 321 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 5 % Grown

The README.md

yii2-importexport

Extension for the Yii2 framework for importing and exporting data with PHPExcel., (*1)

Installation

The preferred way to install this extension is through composer., (*2)

Either run, (*3)

php composer.phar require --prefer-dist boundstate/yii2-importexport "*"

or add, (*4)

"boundstate/yii2-importexport": "*"

to the require section of your composer.json file., (*5)

Usage

Implement the ImportInterface and/or ExportInterface:, (*6)

class Contact extends \yii\db\ActiveRecord implements ImportInterface, ExportInterface
{
    ...

    public function import($reader, $row, $data)
    {
        if ($row == 0) {
            if ($data != ['First Name', 'Last Name', 'Email']) {
                $reader->addError($row, 'Invalid headers.');
                return false;
            }
            // Skip header row
            return true;
        }

        // Create contact from data
        $contact = new Contact;
        ...
    }

    public function export() {
        return self::find()->asArray()->all();
    }
}

Now you can import data using ExcelReader and your class as the destination:, (*7)

public function actionImport()
{
    $form = new ImportForm();
    $form->file = UploadedFile::getInstanceByName('file');

    if ($form->validate()) {
        Contact::deleteAll();
        $reader = new ExcelReader(['destination' => Contact::className()]);
        $reader->import($form->file->tempName);
        if ($reader->getErrors()) {
            // Handle errors
            ...
        }
    }
    return $form;
}

Or export data using ExcelWriter and your class as the source:, (*8)

public function actionExport()
{
    $writer = new ExcelWriter(['source' => Contact::className()]);
    $filename = $writer->write('Excel2007');
    Yii::$app->response->sendFile($filename, 'contacts.xlsx')->send();
}

The Versions

12/08 2016

dev-master

9999999-dev

Extension for the Yii2 framework for importing and exporting data

  Sources   Download

MIT

The Requires

 

by Bound State Software

csv yii2 excel xls xlsx phpexcel phpoffice

12/08 2016

v0.0.3

0.0.3.0

Extension for the Yii2 framework for importing and exporting data

  Sources   Download

MIT

The Requires

 

by Bound State Software

csv yii2 excel xls xlsx phpexcel phpoffice

25/05 2015

v0.0.2

0.0.2.0

Extension for the Yii2 framework for importing and exporting data

  Sources   Download

MIT

The Requires

 

by Bound State Software

csv yii2 excel xls xlsx phpexcel phpoffice

25/05 2015

v0.0.1

0.0.1.0

Extension for the Yii2 framework for importing and exporting data

  Sources   Download

MIT

The Requires

 

by Bound State Software

csv yii2 excel xls xlsx phpexcel phpoffice