如何使用PHP XLSX Writer将图像,报告标题和标题插入到Excel工作表中?

时间:2019-03-19 06:14:20

标签: php excel phpxlsxwriter

Sample Report Header I want to achieve

我想要实现这样的报告标题。如果我使用$writer->writeSheetRow()添加报告标题和副标题,则$writer->writeSheetHeader()不会显示标题行。另外,我无法在工作表中插入图像。如果有任何示例代码,将非常有帮助。预先感谢!

1 个答案:

答案 0 :(得分:0)

在生成Excel之前添加以下代码:

//locate where you have saved your image
$image = imagecreatefromjpeg('images/officelogo.jpg');
$objDrawing = new PHPExcel_Worksheet_MemoryDrawing();
$objDrawing->setName('Sample image');$objDrawing->setDescription('Sample image');
$objDrawing->setImageResource($image);
$objDrawing->setRenderingFunction(PHPExcel_Worksheet_MemoryDrawing::RENDERING_JPEG);
$objDrawing->setMimeType(PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_DEFAULT);
$objDrawing->setHeight(150);
//Then locate where shall the image be placed in the excel, it indicates the UPPER LEFT corner if the image
$objDrawing->setCoordinates('A3');
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());