-1

I have a table, and I want to export the data in this table into an excel file.

But I am having problem formatting the data cells in SKU column.

this is my code for excel

            Excel::store((new  StandardExport($q))->setHeaders([ 
                'SKU',
                'Order Number',
                'Create Date',
                'Update Date',
                'Payment Method',
                'Shipping Provider',
                'Tracking Number',
                'Status',
                'Seller Remark',
                'Buyer Phone',
                'Buyer Name',
                'Buyer Address',
                'Buyer Remark',
                'Shop Name'
               
            ])->setMap(function ($row) {
                return [
                    str_replace("<br>", "\n", $row->sku),
                    $row->order_number,
                    $row->create_at,
                    $row->update_at,
                    $row->paymentMethod,
                    $row->logistics_info,
                    str_replace("<br>", "\n", $row->tracking_number),
                    $row->status,
                    $row->seller_remark,
                    $row->buyer_phone,
                    $row->buyer_name,
                    $row->buyer_address,
                    $row->buyer_remark,
                    $row->shopname
                ];
            }), $filename);

but appeared like this: one line

I want to export excel like this: multiple line

any possible idea?

1 Answers1

0

not 100% sure but this is kinda first idea that pops in my head :D

I'd try counting the column that can be more than 1 so if "master_code" is > 1 in those cases I'd update map in a way to provide multiple rows in data but to put them empty for certain fields..

Basically something like

if($master_code > 1) { 
    // In map do a for loop ($i=0; $i <= $master_code; $i++) 
    // And use nullish ` $preference_no ?? '' ` for empty fields 
} 

This way it should make multiple empty fields if there is no data for it

Note: As I said this is first thing that popped in my head :)

devsead
  • 312
  • 7