Copy sheets without image

Topics: Developer Forum, Project Management Forum, User Forum
Jul 21, 2009 at 3:31 PM
Edited Jul 21, 2009 at 3:36 PM

Hello,

I need to copy a sheet from a Workbook i load before. So i use the function "copy".

It worked but not really correctly.

1) When i open the file generated, i have an error like my data are probably lost.

2) All image of my workbook  are disapeared.

My Code to copy:

 

$objPHPExcel->setActiveSheetIndex($index_obs_suite);
$sheet = $objPHPExcel->getActiveSheet();
$copiedSheet = $sheet->copy();
$copiedSheet->setTitle('OBS Suite Abon '.$nb_obs_suite);
$objPHPExcel->addSheet($copiedSheet);

Also, i tried with:

 

$objPHPExcel->addExternalSheet($copiedSheet);

But not worked too.

 

Without copy, my file generate correctly. Any Idea?

 


Developer
Jul 22, 2009 at 5:31 AM

>> All image of my workbook  are disapeared.

I recall this bug in PHPExcel 1.6.7:
http://phpexcel.codeplex.com/WorkItem/View.aspx?WorkItemId=9937

Can you try with latest source code:
http://phpexcel.codeplex.com/SourceControl/ListDownloadableCommits.aspx

Jul 22, 2009 at 7:50 AM

Thanks for your help but, i have the same errors with last version commited and it show me another error:

Notice: iconv_substr() [function.iconv-substr]: Unknown error (0) in C:\wamp\phenix\www\omicron\appli\lib\excel\Classes\PHPExcel\Shared\String.php on line 307

Before i update with the last version i had the version  27946.

Thx for your hard work!


Jul 22, 2009 at 9:05 AM

Re,

I found a temporary solution to my probleme.

In Classe\PHPExcel\Worksheet.php, we have this code using for copy sheets:

/**
	 * Copy worksheet (!= clone!)
	 *
	 * @return PHPExcel_Worksheet
	 */
	public function copy() {
		$copied = clone $this;

		return $copied;
	}

	/**
	 * Implement PHP __clone to create a deep clone, not just a shallow copy.
	 */
	public function __clone() {
		foreach ($this as $key => $val) {
			if ($key == '_parent') {
				continue;
			}

			if (is_object($val) || (is_array($val))) {
				$this->{$key} = unserialize(serialize($val));
			}
		}
	}
The issue of image come from the function __clone. An image is an object so i just modify like this:

if (is_array($val)) {
        $this->{$key} = unserialize(serialize($val));
}


And it worked. So i think we have to make the difference beetween objects images and others in the condition.

Developer
Jul 23, 2009 at 7:03 AM
Edited Jul 23, 2009 at 7:03 AM

Thank you for your note. The problem I am having right now is that I cannot reproduce the bug. I will try to do some more testing.