我已将此模块分配给我,他们需要在其中通过excel下载文件。我的问题是我似乎无法在Excel文件中以正确的格式填充多个数据。我希望我的代码在下面附加的图像上具有相同的结果。我很难做到这一点,因为我是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');
}