php execl 通过echo简单导出

         //获取数据

        $list=Ativity::getTw_statisticExecl($activity_id,$status);

        // execl导出

        header('Content-Type: application/vnd.ms-excel');
        header('Content-Disposition: attachment; filename=排行统计.xls');
        header('Pragma: no-cache');

        header('Expires: 0');

      //输出表头

        $title = array('编号', '姓名', '电话', '得票数', '排行', '状态');

        echo iconv('utf-8', 'gbk', implode("\t", $title)), "\n";

      //输出内容

        foreach ($list as $key => $value) 
        {
        echo iconv('utf-8', 'gbk', implode("\t", $value)), "\n";

        }

编号 姓名 电话 得票数 排行 状态
85 买路 15116330000 31 1 1
86 测试大爷 15116330006 14 2 1
87 英文不行 14789517896 7 3 1
103 河口 15116330090 6 4 1
89 勒个去 14789510917 4 5 1
88 小爷 15116330001 3 6 1
92 蛮低37 15916978137 3 7 1
93 蛮低36 15916978136 3 8 1
91 蛮低39 15916978139 2 9 0
102 破了 14789510917 2 10 0
94 蛮低31 15916978131 1 11 0
95 蛮低28 15916978128 1 12 0
96 蛮低14 15916978114 1 13 0
97 蛮低12 15916978112 1 14 0
98 蛮低40 15916978140 1 15 0
99 蛮低38 15916978138 1 16 0
100 蛮低35 15916978135 1 17 0
101 蛮低33 15916978133 1 18 0
104 蛮低32 15916978132 1 19 0

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在 Laravel 导出 Excel,你可以使用 Laravel Excel 这个扩展包。下面是简单的步骤: 1. 使用 Composer 安装 Laravel Excel ``` composer require maatwebsite/excel ``` 2. 在 `config/app.php` 文件添加服务提供者和门面 ```php 'providers' => [ // ... Maatwebsite\Excel\ExcelServiceProvider::class, ], 'aliases' => [ // ... 'Excel' => Maatwebsite\Excel\Facades\Excel::class, ], ``` 3. 创建控制器和视图 创建一个控制器来处理 Excel 导出的逻辑,例如 `ExcelController`,并在其创建一个 `export()` 方法来生成 Excel 表格。 ```php namespace App\Http\Controllers; use Illuminate\Http\Request; use Maatwebsite\Excel\Facades\Excel; use App\Exports\UsersExport; class ExcelController extends Controller { public function export() { return Excel::download(new UsersExport, 'users.xlsx'); } } ``` 在 `app/Exports` 目录下创建一个 `UsersExport` 类,用于生成 Excel 数据。 ```php namespace App\Exports; use App\User; use Maatwebsite\Excel\Concerns\FromCollection; class UsersExport implements FromCollection { public function collection() { return User::all(); } } ``` 创建一个视图文件来呈现导出 Excel 表格的按钮,例如 `export.blade.php`。 ```html <a href="{{ route('export') }}">Export Users</a> ``` 4. 定义路由 在 `routes/web.php` 文件定义一个路由,指向 `ExcelController` 的 `export()` 方法。 ```php Route::get('export', 'ExcelController@export')->name('export'); ``` 现在,当用户访问 `/export` 路径时,会生成一个名为 `users.xlsx` 的 Excel 文件,包含用户数据。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值