dpjs2005 2019-02-13 02:08
浏览 39

有没有办法在excel中为所有选定的选项动态填充适当格式的数据?

I have this module assigned to me where they need to download the file via excel. My problem is that I can't seem to populate multiple data with proper format in the excel file. I want my code to have the same results on the image I attached below. I am having a hardtime doing it right because I am new to PHPExcel.

 function getDownloadTags($selected)
{


 $dataExcel = Excel::create('Download Tags');

$ids = explode(',', $selected);
$list = Product::byIds($ids);
//dd($input);

    $dataExcel->sheet('Tags' , function($sheet) use ($list){

        $rowcnt = 0;

        foreach($list as $row){
            $colors = Color::Bydept($row->dept,$row->colors);
            $color_labels = '';
            foreach($colors as $color){
                $color_labels = $color_labels.$color['name'].',';
            }
            $color_labels = substr($color_labels, 0,-1);
            $sizes = Size::byDept($row->dept,$row->sizes);
            $size_labels = '';
            foreach($sizes as $size){
                $size_labels = $size_labels.$size['name'].',';
            }
            $size_labels = substr($size_labels, 0,-1);


            if($color_labels == false){
            $color_labels = '';
            }
            //dd($row);
            if($size_labels == false){
            $size_labels = '';
            }
            $exp_del = substr_replace($row->exp_deli_month, '/1', 2, 0);
            $img = public_path("qr-code//".$row->barcode . ".png" );
        $rowcnt++;

        $objDrawing = new PHPExcel_Worksheet_Drawing;


        $headingsCss = array(
            "Date" . "                                        " . date('M j, Y', strtotime($row->sampling_date)) ,

        );
        $Vendor = array(
            "Vendor" . "                                  " . $row->vendor_name ." " . $row->vendor ,   
        );

        $Department = array (
            "Department" . "                        " . str_replace('^', "'", $row->dept_name) ,
        );

        $empspace1 = array(

                " ",
        );

        $color_child_label = "";
        if(!empty($row->color_child))
        {
            $color_child = \App\Color::Bydept($row->dept,$row->color_child);
            //var_dump($color_child); 
            $color_child_label = [];
            foreach ($color_child as $color_child_name) {
                $color_child_label = ' - ' . $color_child_name->name;
            }
        }

        $bold = array(
             strtoupper($row->description) . $color_child_label,
        );

        $stock = array(
            "Vendor Stock Code" .  "           "  . $row->stock_code, 
        );
        $colors = \App\Color::Bydept($row->dept,$row->colors);
        $color_labels = [];
        foreach($colors as $color){
            $color_labels[] = $color->name;
        }               
        $colors = array(
            "Colors".  "                                     "  . implode(', ',$color_labels),
        );
        $sizes = array(
            "Sizes" . "                                       " . $row->sizes,
        );
        $Availableqty = array(
            "Available Qty" .  "                      "  .$row->avail_qty,
        );

        $footer = array(
            "COST" . "\br" .  $row->cost,

        );


        $sheet->appendRow(1, $headingsCss);
        $sheet->appendRow(2, $Vendor);
        $sheet->appendRow(3, $Department);
        $sheet->appendRow(4, $empspace1);
        $sheet->appendRow(4, $empspace1);
        $sheet->appendRow(6, $bold);
        $sheet->appendRow(7, $stock);
        $sheet->appendRow(8, $colors);
        $sheet->appendRow(9, $sizes);
        $sheet->appendRow(10,$Availableqty);
        $sheet->prependRow(5, $empspace1);
        $sheet->appendrow($sizes,6);
        $sheet->appendrow(11,$footer);

        $objDrawing->setPath($img);
        $objDrawing->setCoordinates('B'.$rowcnt);
        $objDrawing->setOffsetX(15);
        $objDrawing->setWidthAndHeight(104,104);
        $objDrawing->setResizeProportional(true);
        $objDrawing->setWorksheet($sheet);

         $sheet->setWidth(array(
            'A'     =>  50,
            'B'     =>  25,
            'C'     =>  25,
            'D'     =>  25,
            'E'     =>  25,
            'F'     =>  25,
            'G'     =>  25,
            'H'     =>  30,
            'I'     =>  25,
            'J'     =>  25,
        ));


        $dataExcel->setActiveSheetIndex(0);
    $dataExcel->download('xlsx');



}

I expect an output like THIS when 2 products are selected. But instead I got this. I can only populate one at a time.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度