yarisrespect / yii2-excel

使用 PHPExcel 导入 *.xls 文件到 Yii 2 框架

安装: 523

依赖: 0

建议者: 0

安全: 0

星标: 3

关注者: 2

分支: 2

类型: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

使用 PHPExcel 导入 *.xls 和 *.xlsx 文件到 Yii 2 框架

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(); ?>