我正在尝试使用PHPSpreadsheet库在Xlsx文档的页脚中动态插入图像。
我试图修改文档样本,但是在打印文档时什么也没出现。
$inputFileName = './tpl1.xlsx';
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($inputFileName);
$sheet = $spreadsheet->getActiveSheet();
$drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\HeaderFooterDrawing();
$drawing->setName('PhpSpreadsheet logo');
$drawing->setPath('./uploads/blu.png');
$drawing->setHeight(36);
$sheet->getHeaderFooter()->addImage($drawing, \PhpOffice\PhpSpreadsheet\Worksheet\HeaderFooter::IMAGE_FOOTER_CENTER);
$sheet->getHeaderFooter()->setOddHeader('&C&G');
一些想法?
答案 0 :(得分:0)
您必须更改setOddHeader
'/opt/lampp/htdocs/www'
到
docker exec -i 9498f0e1c5066f060c0e9439faa744cc39208ee27fc0dbe0d54075c683748137 bash -c 'cat > /www/aaa.csv' < /opt/lampp/htdocs/www/aaa.csv
$sheet->getHeaderFooter()->setOddHeader('&C&G');
和$sheet->getHeaderFooter()->setOddFooter('&C&G');
必须彼此对应。
您应该设置宽度,例如:HeaderFooter::IMAGE_FOOTER_CENTER
完整代码应如下所示:
&C&G