0

this actual number

6471050909740010

and get replace by excel here the result

6.47105E+15

6471050909740000

This my code

$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);
             }
        });

    });

data inside $collect all is string event the number store as string

Aslam H
  • 1,669
  • 4
  • 21
  • 46
  • 1
    Maybe you want to take a look at [Column Formatting](https://laravel-excel.maatwebsite.nl/3.1/exports/column-formatting.html#formatting-columns) – Mozammil Jan 20 '19 at 10:30

2 Answers2

2

I think you can do the following

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

instead of

$sheet->cell('H'.$i, $empid);
Ali Mrj
  • 71
  • 6
0

Larvel maatwebsite/excel version 2.*

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']);
        }
    });
});
Aslam H
  • 1,669
  • 4
  • 21
  • 46