yarisrespect / yii2-excel
使用 PHPExcel 导入 *.xls 文件到 Yii 2 框架
dev-master
2015-05-20 09:59 UTC
Requires
- php: >=5.4.0
- phpoffice/phpexcel: *
- yiisoft/yii2: *
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(); ?>