0

Here I attached my recent Laravel-excel image. Here I mark $items_name column. Which I want to need in multiple columns. For that reason I use foreach loop, and implode and also array_map. [1]: https://i.sstatic.net/PaMM3.jpg

I want to show $item_name values in different columns not in a single column.

if($customer_type == 2)
    {
        $excel_data_attribute = array(
            array('Distributor Customer')
        );

        if ($show_type == 0)
        {
            $excel_data_attribute_array = array(
                array('Sales Sheet - Quanty Wise')
            );
        }elseif($show_type == 1)
        {
            $excel_data_attribute_array = array(
                array('Sales Sheet - Price Wise')
            );
        }else
        {
            $excel_data_attribute_array = array(
                array('Sales Sheet - Cartoon Quanty Wise')
            );
        }
        $excel_dynamic_data_array = array();
        $index=0;
        foreach ($productGroup as $gKey => $group )
        {
            $col_[$gKey] = false;
            foreach($all_product as $pkey => $product)
            {
                if($productGroup[$gKey]["id"] == $product->product_group_id)
                {
                    $col_[$gKey] = true;
                }
            }
            if($col_[$gKey])
            {
                $product_Names_with_keys = $productGroup[$gKey]["t_product"].$productGroup[$gKey]['gorupName'];

                $excel_dynamic_data_array[$index][] = $productGroup[$gKey]['gorupName'];
                $index++;
            }
        }
        $item  = $excel_dynamic_data_array;

        $item_name = implode(', ', array_map(function ($entry) {
                                                return ($entry[key($entry)]);
                                            }, $item));
        if($summery == 1)
        {
            $excel_data_attribute_array_column = array(
                array('SL','Region & Rsm',$item_name,'Total')
            );
        }else
        {
            if ($customer_type == 2)
            {
                $excel_data_attribute_array_column = array(
                    array('SL','Order No','Order Date','Challan No','Challan Date','Bill No','Party Name','Area',$item_name,'Total')
                );

            }else
            {
                $excel_data_attribute_array_column = array(
                    array('SL','Order No','Order Date','Bill No','Party Name','Area',$item_name,'Total')
                );
            }
        }
        $total_final_array = array_merge($excel_data_attribute,$excel_data_attribute_array,$excel_data_attribute_array_column);
    }
   return collect($total_final_array); 

2 Answers 2

1

Try this,

array_merge(array('SL','Order No','Order Date','Challan No','Challan Date','Bill No','Party Name','Area','Total'),explode(',',$item_name));
Sign up to request clarification or add additional context in comments.

2 Comments

Got this error after using this.... TypeError Return value of Maatwebsite\Excel\Sheet::mapArraybleRow() must be of the type array, string returned
Then I write this- $excel_data_attribute_array_column = array( array_merge(array('SL','Order No','Order Date','Challan No','Challan Date','Bill No','Party Name','Area'),explode(',',$item_name),array('Total')) );
0
$excel_data_attribute_array_column = array(
      array_merge(
        array('SL','Order No','Order Date','Challan No','Challan Date','Bill No','Party Name','Area'),
        explode(',',$item_name),
        array('Total')
      )
 );

Correct ans is-

2 Comments

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
I just explode which column I want to separate.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.