how to protect image

Topics: Developer Forum, Project Management Forum, User Forum
Nov 14, 2009 at 5:57 AM

i need to protect image.

how to fix this image should not be movable.

waiting for reply

Developer
Nov 14, 2009 at 6:18 AM

Images are locked by default, but you need to set sheet protection:

$worksheet->getProtection()->setSheet(true);
$worksheet->getProtection()->setObjects(true);

Are you using Excel5 or Excel2007 writer?

Nov 14, 2009 at 6:58 AM

still it is not working

i'm using excel 5 writer

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');

one  more question how to set width of image?

like as we set height for image $objDrawing->setHeight(50);

Developer
Nov 14, 2009 at 7:21 AM

>> still it is not working i'm using excel 5 writer

Sheet protection options have not yet been implemented for Excel5 reader/writer. Work item created. Will put it on the to-do list for next week.

http://phpexcel.codeplex.com/WorkItem/View.aspx?WorkItemId=10939

>> one  more question how to set width of image?

It should be working. But if you are trying to set non-proportional width/height you need to use setResizeProportional(false):

$worksheet = $excel->getActiveSheet();
$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setPath('./images/panda.jpg');
$objDrawing->setResizeProportional(false);
$objDrawing->setWidth(200);
$objDrawing->setHeight(20);
$objDrawing->setCoordinates('B15');
$objDrawing->setWorksheet($worksheet);
Developer
Nov 16, 2009 at 5:41 AM

Download latest source code in a couple of hours:

http://phpexcel.codeplex.com/SourceControl/ListDownloadableCommits.aspx