0

I've been using laravel excel to download array data for a few weeks and all of a sudden today, the download won't open.

It gives an incorrect extension type (xlsx) and says it may be corrupted.

There is no whitespace before my <?php tag and there is no closing tag at all. No changes have been made to the file and the downloads were working otherwise. Is there a reason this would occur now? Is it possible it has to do with the output buffer?

I really don't want to store and return download but I want to keep it as Excel.

Maybe there's something that's clear here

public function exportCatalog($id, $company){

    $allgroupResult= array();
    $rowCount = 2;
    $boldRows = array();


    $name = 'Export For ' . $id . ' Company ' . $company;

    $build = Excel::create($name, function ($excel) use ($allgroupResult) {

        $excel->setTitle('Catalog Export');

        $excel->sheet('Catalog Export', function ($sheet) use ($allgroupResult) {

            $sheet->fromArray($allgroupResult);

            foreach ( $boldRows as $row )   {
                $cell_name = excelColumnFromNumber($row)."1";
                $sheet->getStyle( $cell_name )->getFont()->setBold( true );
            }

            // freeze the header row
            $sheet->freezeFirstRow();

            // set header names
            $sheet->row(1, [
                'Product Images',
                'Product Images',
                'Product Images',
                'Product Images',
                'Product Images',
                'Product Images',
                'Product Images',
                'Product Images',
                'Product Images',


            ]); // column headers

            // set the width for the columns that are used 
            $sheet->setWidth('A', 10);
            $sheet->setWidth('B', 15);
            $sheet->setWidth('C', 10);
            $sheet->setWidth('D', 10);
            $sheet->setWidth('E', 10);
            $sheet->setWidth('F', 10);
            $sheet->setWidth('G', 10);
            $sheet->setWidth('H', 60);
            $sheet->setWidth('I', 10);

        });

    })->download('xlsx');

}
Geoff_S
  • 4,917
  • 7
  • 43
  • 133
  • Have you checked what the generated file contains? Is there an error message hidden in the downloaded file? – Nico Haase Feb 06 '19 at 16:33
  • I can't check the file itself because I can't open it, since it's corrupted. At least, I don't know of a way to – Geoff_S Feb 06 '19 at 16:35
  • Of course you can open it - usually, each OS comes with some kind of text editor like Notepad – Nico Haase Feb 06 '19 at 16:37
  • 1
    open the excel file as a "text" file in notepad/sublime text to see any error message there. Better check log files too. – Sakibul Alam Feb 06 '19 at 16:38
  • @NicoHaaseI have plenty of text editors, but I still can't open it in them. Even trying to convert to text with online services fails – Geoff_S Feb 06 '19 at 16:42
  • @SakibulAlam I was able to save as XLS, still error, but I can open it with errors and it just has a lot of foreign characters around the data – Geoff_S Feb 06 '19 at 16:47
  • Ok so if I download as a CSV file it works and has an empty first row – Geoff_S Feb 06 '19 at 16:57
  • @TomN., are you sure `$boldRows` are defined in the scope, you haven't extended the scope in `use` of the callbacks. – Sakibul Alam Feb 06 '19 at 19:03

0 Answers0