简体   繁体   English

在laravel maatwebsite中以导出CSV格式设置标题的背景颜色

[英]Set background color for heading in export CSV format in laravel maatwebsite

I am trying to set background color for the below export CSV file. 我正在尝试为以下导出CSV文件设置背景色。 But background color is not setting for the first row. 但是没有为第一行设置背景色。 Its only works for the xls format. 它仅适用于xls格式。 Please help. 请帮忙。 Thanks in advance. 提前致谢。

$fileName = $filename."_".date('dmYHis');                                                                                                                       
        \Excel::create($fileName,function($excel) use($newarray){
            $excel->setTitle('Tasks');
            $excel->setCreator('Admin');
            $excel->setCompany('Company');
            $excel->setDescription('Time Sheet');
            $excel->sheet('sheet1',function($sheet) use($newarray){                             
                $sheet->fromArray($newarray, null, 'A1', false, false);
                $sheet->cells('A1:N1', function($cells) {
                         $cells->setBackground('#AAAAFF'); 
                });
            });

        })->download('csv');                                                            

Comma-separated values (CSV) file stores tabular data (numbers and text) in plain text , so you can't assign a background color in a CSV file. 逗号分隔值(CSV)文件以纯文本格式存储表格数据(数字和文本),因此您无法在CSV文件中分配背景色。 You should use Excel (xls or xlsx) format. 您应该使用Excel(xls或xlsx)格式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM