本文介绍了使用PHP Excel将徽标添加到Excel工作表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正尝试使用下面的代码在生成的excel工作表上添加徽标图像,但是由于某种原因,它什么都不做
I am trying to add a logo image on a generated excel worksheet using the code listing below but for some reason it does nothing
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objPHPExcel = $objReader->load("workbooks/" . $labref . "/" . $labref . ".xlsx");
$objPHPExcel->getActiveSheet(2);
$objWorkSheet = $objPHPExcel->createSheet();
$objWorkSheet->setTitle("Sample Summary");
$dir1 = "exclusive_image";
$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setName("name");
$objDrawing->setDescription("Description");
$objDrawing->setPath(base_url().'exclusive_image/nqcl.png');
$objDrawing->setCoordinates('A1');
$objDrawing->setWorksheet($objWorkSheet->getActiveSheet(2));
$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
$objWriter->save("workbooks/" . $labref . "/" . $labref . ".xlsx");
推荐答案
添加徽标非常简单,请尝试以下代码.
Adding logo is so simple, try below code.
$objPHPExcel = new PHPExcel();
$sheet = $objPHPExcel->setSheetIndexAndTitle(1, "YOUR_SHEET_TITLE"); // first sheet
$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setName('Logo');
$objDrawing->setDescription('Logo');
$logo = base_path() . '/images/logo.png'; // Provide path to your logo file
$objDrawing->setPath($logo);
$objDrawing->setOffsetX(8); // setOffsetX works properly
$objDrawing->setOffsetY(300); //setOffsetY has no effect
$objDrawing->setCoordinates('B1');
$objDrawing->setHeight(75); // logo height
$objDrawing->setWorksheet($sheet);
这篇关于使用PHP Excel将徽标添加到Excel工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!