on CSV export from laravel blade view skip last blank td

Viewed 164

Laravel maatwebsite export function skip last blank td from view while exporting , I want to show blank columns instead skipping it.

I made some changes in export config file

export.php

'exports' => [
'strict_null_comparison' => true,
'csv'                    => [
            'delimiter'              => ';',
            'enclosure'              => '',
            'line_ending'            => PHP_EOL,
            'use_bom'                => false,
            'include_separator_line' => false,
            'excel_compatibility'    => false,
        ],
],

my controller is

public function flushExcelReport(Request $request){
$final      = [];
      $rows = $this->generateReportData($request->id);
                if (!empty($rows)) {
                    foreach ($rows as $entries) {
                        foreach ($entries as $key => $row) {
                            $final[] = $row;
                        }
                    }
                }
   return Excel::download(new ReportExport($final), 'final.csv', \Maatwebsite\Excel\Excel::CSV,['Content-Type' => 'text/csv',]);
}

ReportExport


namespace App\Exports;

use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
use Maatwebsite\Excel\Concerns\WithStrictNullComparison;
class ReportExport implements FromView,WithStrictNullComparison
{
    private $data;
   public function __construct($data)
   {
       $this->data = $data;
   }
    public function view(): View
    {
        return view('report', ['final' => $this->data]);
    }
}

report.blade

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
  <table class="table">
    <tbody>
    @foreach($final as $row)    
      <tr>
        <td>{{ $row['sapNo'] }} </td>
        <td>{{ $row['month'] }} </td>
        <td>1110</td>
        <td>{{ $row['totalHours'] }}</td>
        <td>{{ $row['netPricePerHour'] }}</td>
        <td></td>        
        <td></td>        
        <td></td>        
      </tr>   
      @endforeach
      </tbody>
  </table>
</body>
</html>

I have created 3 blank in view file on export i cant see respected place or blank column in csv

excel file data is enter image description here

I want it should look like enter image description here

can anyone help me how do i stop maatwebsite/Excel skipping blank td

0 Answers
Related