yarisrespect/yii2-excel

Import *.xls by PHPExcel for Yii 2 framework

Installs: 523

Dependents: 0

Suggesters: 0

Security: 0

Stars: 3

Watchers: 2

Forks: 2

Type:yii2-extension

dev-master 2015-05-20 09:59 UTC

This package is not auto-updated.

Last update: 2020-09-04 20:37:26 UTC


README

Import *.xls, *.xlsx by PHPExcel for Yii 2 framework

Model.php:

public function behaviors() {
    return [
      ImportBehavior::className()
    ]
}
public function onImportRow($row, $index, $max_row) {
    $this->addLog( implode(', ', $row). " ($index/$max_row)" );
    return true; // return FALSE to stop import
}

Controller.php:

public function actionImport() {
    $model = new Model();
    $model->importExcel();
    return $this->render('import', [ 'model' => $model ]);
}

View import.php:

<? $form = ActiveForm::begin([ 'options' => [ 'enctype' => "multipart/form-data", ] ]); ?>

    <?= \yarisrespect\excel\ImportFileWidget::widget([
        'model' => $model, 'form' => $form, 'label' => 'File'
    ])?>
    <?= Html::submitButton('Import') ?>
    <?= \yarisrespect\excel\ImportLogWidget::widget([ 'model' => $model, ])?>
    
<? ActiveForm::end(); ?>