$spreadsheet = new Spreadsheet();
$objSheet = $spreadsheet->getActiveSheet();
$dir = $_SERVER['DOCUMENT_ROOT'];
foreach ($body as $key => $val) {
$row = $key + 2;
$col = 0;
foreach ($val as $v) {
if (strpos($v, 'jpg') === false && strpos($v, 'png') === false && strpos($v, 'jpeg') === false) {
$sheet->setCellValue($char_index[$col] . $row, $v);
}
$col++;
}
if ($val['content']) {
$this->download($val['content'], $dir, $row, $objSheet, 'H');
}
if ($val['budget_content']) {
$this->download($val['budget_content'], $dir, $row, $objSheet, 'L');
}
if ($val['stock_content']) {
$this->download($val['stock_content'], $dir, $row, $objSheet, 'P');
}
if ($val['check_content']) {
$this->download($val['check_content'], $dir, $row, $objSheet, 'W');
}
$objSheet->getRowDimension($row)->setRowHeight(80);
}
$objSheet->setTitle($title);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="' . $name . '.xlsx"');
header('Cache-Control: max-age=0');
$objWriter = IOFactory::createWriter($spreadsheet, 'Xlsx');
$objWriter->save('php://output');
exit();
private function download($val, $dir, $row, $objSheet, $key)
{
$content = explode(',', $val);
foreach ($content as $k => $value) {
$file_info = pathinfo($value);
$basename = $file_info['basename'];
$dirname = $file_info['dirname'];
is_dir($dir) or mkdir($dir, 0777, true);
file_put_contents($dir . $dirname . '/' . $basename, file_get_contents($dir . $dirname . '/' . $basename));
$drawing[$row] = new Drawing();
$drawing[$row]->setName('GoodsCode');
$drawing[$row]->setDescription('GoodsCode');
$drawing[$row]->setPath($dir . $value);
$drawing[$row]->setWidth(30);
$drawing[$row]->setHeight(80);
$drawing[$row]->setCoordinates($key . $row);
$drawing[$row]->setOffsetX(0);
$drawing[$row]->setOffsetY(0);
$drawing[$row]->setWorksheet($objSheet);
}
}