$objDrawing->setPath() and passing arguments

Topics: Developer Forum, Project Management Forum
Jan 26, 2010 at 7:22 AM

I'm currently using PHPExcel 1.6.7

I have PHP script that generates images according some arguments. It is available by link like http://somedoma.in/test.php?arg1=val1&arg2=val2&arg3=val3

Is there any ways to include such images in project?


I can access this script directly from the filesystem. I tried to pass arguments like $objDrawing->setPath("test.php arg1=val1 arg2=val2 arg3=val3"); but it looks like "test.php arg1=val1 arg2=val2 arg3=val3" is a filename, not file with arguments.

Well, I can fetch it by file_get_contents() or something else, save the file, add to the project and delete it. I can rather add timestamp and/or random value to avoid file name collisions. but... I think this isn't a good idea at all.

Probably it would be better to add images stream (that are got by file_get_contents()) directly to the project avoiding saving files. But I didn't find any methods like that.

Jan 27, 2010 at 9:53 AM

Agreed. Adding this as a note to work item


The problem is that images are generally not a part of PHPExcel's in-memory representation of the workbook at the moment. When this is fixed it should be easier to address your request.


Mar 27, 2012 at 5:52 AM

@azriman   I have the same issue. Adding a generated image to an Excel worksheet (http://somedoma.in/test.php?arg1=val1&arg2=val2&arg3=val3)

Did you use either of the two workarounds you mentioned?

I had a look at the May 2009 workitem but it currently has a "Proposed" status so it looks like it will be a while before a permanent solution appears.

With koyama's comment of the image not being part of the in-memory representation i would imagine only your first suggestion of creating a temporary file, adding it to the workbook and then deleting it after the workbook was generated would be possible.

Mar 28, 2012 at 10:15 PM

@koyama I created an Excel 2007 document and looked at the differences between an image that is stored in the workbook archive and one that was external and only loaded when the workbook was opened.
In the xl\drawings\_rels\drawing1.xml.rels the only difference was the image that was sourced externally to the workbook had TargetMode="External" in the Relationship element.
The externally sourced image also allowed the additional parameters/arguments that azriman was after. http://somedoma.in/test.php?arg1=val1&arg2=val2&arg3=val3
Would it be possible to to have an option on the $objDrawing->setPath() function to tell it to create an TargetMode="External" image? Then it would know not to attempt to find the file and attach it but rather just create the entry with the TargetMode="External" parameter.
This is all new to me but hopefully this is a valid suggestion. :)