Yii2 导入导出Excel
来源:互联网 发布:seo网络营销技术 编辑:程序博客网 时间:2024/06/05 23:03
前两天做excel导入的工作,发现网上关于导出的很多,而导入的几乎寥寥,顺手整理一下导入导出。
yii2 excel导入
$fileName = '/www/test.xlsl'; $tag_data = \moonland\phpexcel\Excel::import($fileName, [ 'setFirstRecordAsKeys' => true, 'setIndexSheetByName' => true, 'getOnlySheet' => 'sheet1', ]);//$tag_data = ['mm','xx']; //批量插入 Yii::$app->wxDb->createCommand()->batchInsert( 'tag', ['tag_name'], $tag_data )->execute();
yii2 excel导出
use moonland\phpexcel\Excel; /* * 根据条件导出报名数据 */ public function actionPhpexcel($classroom_id) { $url = Yii::$app->request->referrer; $enroll = new ClassroomEnroll(); $enroll = $enroll->find()->all(); Excel::export([ 'models' => $enroll, 'fileName' => $enroll[0]['classroom']['title'].'-报名', 'columns' => [ [ 'attribute' => 'title', 'header' => '课堂', 'format' => 'text', 'value' => function ($models) { return $models['classroom']['title']; } ], [ 'attribute' => 'order_no', 'header' => '订单号', 'format' => 'paragraphs', 'value' => function ($models) { return strip_tags($models['order_no']); } ], [ 'attribute' => 'price', 'header' => '价格', 'format' => 'text', 'value' => function ($models) { return intval($models['price'])>0 ?round($models['price']/100,2) : $models['price']; } ], [ 'attribute' => 'truename', 'header' => '报名者', 'format' => 'text', 'value' => function ($models) { return $models['user']['truename']; } ], [ 'attribute' => 'mobile', 'header' => '手机号', 'format' => 'text', 'value' => function ($models) { return $models['user']['mobile']; } ], [ 'attribute' => 'corp', 'header' => '公司', 'format' => 'text', 'value' => function ($models) { return $models['user']['corp']; } ], [ 'attribute' => 'position', 'header' => '职位', 'format' => 'text', 'value' => function ($models) { return $models['user']['position']; } ], [ 'attribute' => 'status', 'header' => '支付状态', 'format' => 'text', 'value' => function ($models) { return $models['order_status'] == 1 ? '已支付' : '未支付'; } ], ] ]); return yii::$app->util->alert('导出成功',$url); }
0 0
- Yii2 导入导出Excel
- yii2.0 利用Excel类做导入导出
- yii2::导出Excel
- 导入/导出Excel
- 导入/导出Excel
- 导入/导出Excel
- 导入/导出Excel
- EXCEL导入导出
- Excel导入&导出
- 数据库导入导出Excel
- 导入/导出Excel
- 导入/导出Excel
- 导入/导出Excel
- 导入/导出Excel
- 导入/导出Excel
- excel导入、导出数据
- 导入/导出Excel
- 导入/导出Excel
- mysql安装问题
- 安装Mysql后利用SQLyogEnt启动是提示“access denied for user 'root'@'localhost'(using password:YES)”
- Linux下运行第一个JAVA程序
- exercise 37 符号复习-待续
- Linux平台总线驱动设备模型
- Yii2 导入导出Excel
- [准确]判断PHP键值数组是否存在,使用empty或isset或array_key_exists
- java多线程concurrent包
- Mac-安装gradle
- [Leetcode] 60. Permutation Sequence 解题报告
- yii2 常用ActiveForm表单样式用法总结
- 火星人永久家园建立在何处?
- python 3.4 error: Microsoft Visual C++ 10.0 is required(Unable to find)亲测解决办法
- Leetcode 3. Longest Substring Without Repeating Characters