Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何设置存储为文本的数字laravel excel?_Laravel_Laravel Excel - Fatal编程技术网

如何设置存储为文本的数字laravel excel?

如何设置存储为文本的数字laravel excel?,laravel,laravel-excel,Laravel,Laravel Excel,这个实际数字 6471050909740010 并在此处用excel替换结果 6.47105E+15 6471050909740000 这是我的密码 $collect = collect($model->toArray()); $excelData = Excel::create('Endorsement', function($excel) use ($collect) { $excel->sheet('Endorsement', functio

这个实际数字

6471050909740010
并在此处用excel替换结果

6.47105E+15

6471050909740000
这是我的密码

$collect = collect($model->toArray());

$excelData = Excel::create('Endorsement', function($excel) use ($collect) {

             $excel->sheet('Endorsement', function ($sheet) use ($collect) {

             $this->template($sheet);

             foreach ($collect as $key => $rest) {
                $empid = strval($rest['empid']);

                $i = $key+2;
                $sheet->cell('A'.$i, $rest['ttype']);
                $sheet->cell('H'.$i, $empid);
             }
        });

    });

$collect
中的数据都是字符串事件,数字存储为字符串

我认为您可以执行以下操作

$sheet->setCellValue('H'.$i, $empid);
而不是

$sheet->cell('H'.$i, $empid);

Larvel
maatwebsite/excel
Version2*

Excel::create('Endorsement', function ($excel) use ($collect) {

    $excel->sheet('Endorsement', function ($sheet) use ($collect) {

        $sheet->setColumnFormat(array(
            'H' => \PHPExcel_Style_NumberFormat::FORMAT_TEXT,
            'AS' => \PHPExcel_Style_NumberFormat::FORMAT_TEXT,
        ));

        $this->template($sheet);

        foreach ($collect as $key => $rest) {

            $i = $key + 2;

            $sheet->setCellValueExplicit('H' . $i, $rest['empid']);
            $sheet->setCellValueExplicit('AS' . $i, $rest['account_no']);
        }
    });
});

也许你想看看