Laravel excel not exporting in correct format

时间秒杀一切 提交于 2019-11-29 18:14:28

I guess (and it is only a guessing) the header generation fails you here. Try to manipulate your data to have the same indexes for every column (NOTE: CODE IS UNTESTED, you may have to correct it):

$allCategoryResult= array();

foreach($prices->categories as $category){ 
    $categoryItem = array(); 
    $categoryItem["column1"] = $category->category_code;
    $categoryItem["column2"] = $category->category_name; 
    $categoryItem["column3"] = $category->category_desc;

    array_push($allCategoryResult, $categoryItem);    

    foreach($category->skus as $sku){
        $skuItem = array(); 

        $skuItem["column1"] = $sku->sku_info->identifier;
        $skuItem["column2"] = $sku->sku_info->item->description;
        $skuItem["column3"] = $sku->sku_info->item->item_type->count;

        /* We leave that one out for the start
        $skuItem["details"] = array(); 
        foreach ($sku->sku_info->details as $details) {
            $detailsItem = array(); 
            $detailsItem["detail_code"] = $details->detail_code;
            $detailsItem["detail_code2"] = $details->detail_code2;
            $detailsItem["detail_specifier"] = $details->detail_specifier;
            $skuItem["details"][] = $detailsItem; 
        }*/

        $skuItem["column4"] = get_object_vars($sku->prices);

        array_push($allCategoryResult, $skuItem);    
    }
}

This should give you a array with data like that:

Array(
  Array(
    ['column1'] = ...
    ['column2'] = ...
    ... 
  ),
  Array(
    ['column1'] = ...
    ['column2'] = ...
    ... 
  )
)

Please inform me if that does any change to your excel. That would be a basic understanding of the library which will help us to help you.

To answer your comment, it is possible to call the native phpExcel function on your sheet and excel object. So you could use that to format a row bold:

$sheet->->getStyle('A1:'.$sheet->getHighestColumn().'1')->getFont()->setBold(true);

Please read into phpExcel to understand what laravel excel really does, it will help you a lot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!