-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cloned worksheet updates reflected on original (Drawing) #92
Comments
Can you demonstrate the bug by code only (without the need to write and open an xlsx file) ? |
@PowerKiKi Here you go:
I have glued this from pieces of actual code so let's not get hold up on the code quality Outcome:
|
I can take a look at this issue, and see if I can help. Sounds like a good weekend project :) |
@ankitm123 your help would be, once again, appreciated |
After taking a look at the code, there seems to be an issue here: I do understand that unserialize(serialize) has side effects as well as performance issues, but it does fix the issue of circular references. Here are the passing tests. Let me know if this works for you, I will go ahead and submit a PR. |
@ankitm123 I did play around with that clone function, not sure if I ever actually tried to remove that condition all together. Will give it a try and let you know |
That was introduced in 5e27d03 and is related to that old issue. Maybe that can help you dig further... |
@PowerKiKi Yes, I see the issue now. It shows a symbol for the image in the excel file when I comment out the case for drawingCollection. I will dig a bit deeper into this issue. Thanks for the link. @Tomino2112, I think you will also see the same thing, a symbol and not the image itself in the cell. |
@Tomino2112 and @PowerKiKi, did you get time to check my commit? I did try running @Tomino2112's code, and this time, the drawing location on the original sheet did not change. I also wrote it to an xslx file, and it shows the image correctly. Let me know if that works for you. |
This is the code sample I used (copy paste from @Tomino2112): require '../vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\{Spreadsheet,Worksheet\MemoryDrawing,IOFactory};
$image = 'some image!';
$excelOb = new Spreadsheet();
$excelOb->getProperties()->setCreator("Tomas")
->setLastModifiedBy("Tomas")
->setTitle("Test for #92");
// Select sheet
$excelOb->setActiveSheetIndex(0);
// St title
$excelOb->getActiveSheet()->setTitle("Sheet_1");
// Resample image
$orig = imagecreatefrompng($image);
$imgWidth = imagesx($orig);
$imgHeight = imagesy($orig);
$target = imagecreatetruecolor($imgWidth, $imgHeight);
imagealphablending($target, false);
imagesavealpha($target, true);
imagecopyresampled($target, $orig, 0, 0, 0, 0, $imgWidth, $imgHeight, $imgWidth, $imgHeight);
// Add image to sheet
$objDrawing1 = new MemoryDrawing();
$objDrawing1->setName('Sample image');
$objDrawing1->setDescription('Sample image');
$objDrawing1->setImageResource($target);
$objDrawing1->setRenderingFunction(MemoryDrawing::RENDERING_PNG);
$objDrawing1->setMimeType(MemoryDrawing::MIMETYPE_DEFAULT);
$objDrawing1->setCoordinates("E2");
$objDrawing2 = new MemoryDrawing();
$objDrawing2->setName('Sample image');
$objDrawing2->setDescription('Sample image');
$objDrawing2->setImageResource($target);
$objDrawing2->setRenderingFunction(MemoryDrawing::RENDERING_PNG);
$objDrawing2->setMimeType(MemoryDrawing::MIMETYPE_DEFAULT);
$objDrawing2->setCoordinates("G10");
$objDrawing1->setWorksheet($excelOb->getActiveSheet());
$objDrawing2->setWorksheet($excelOb->getActiveSheet());
// Clone sheet
// @note: Doing copy() vs clone does not make difference
$newSheet = clone $excelOb->getActiveSheet();
$newSheet->setTitle("Sheet_2");
$excelOb->addSheet($newSheet);
$newSheet->insertNewRowBefore(1, 1)->insertNewColumnBeforeByIndex(0, 1);
for($i = 0; $i < 7; $i++){
$newSheet->insertNewRowBefore(1, 1);
}
for($i = 0; $i < $excelOb->getSheetCount(); $i++){
echo "Drawing location on sheet \"" . $excelOb->getSheet($i)->getTitle() . "\": " . $excelOb->getSheet($i)->getDrawingCollection()[0]->getCoordinates(). "<br />";
echo "Drawing location on sheet \"" . $excelOb->getSheet($i)->getTitle() . "\": " . $excelOb->getSheet($i)->getDrawingCollection()[1]->getCoordinates(). "<br />";
}
$writer = IOFactory::createWriter($excelOb, "Xlsx");
$writer->save("fix92.xlsx"); I think the commit fixes the bug. If not, please let me know. I will take a look again. |
@Tomino2112 will you be able to test @ankitm123's solution is the coming days ? |
Hi, sorry was away from pc, will test in couple of hours.
…On Mar 6, 2017 05:56, "Adrien Crivelli" ***@***.***> wrote:
@Tomino2112 <https://github.com/Tomino2112> will you be able to test
@ankitm123 <https://github.com/ankitm123> is the coming days ?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#92 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABFl-VGCTA-xJll_m0vACly20zvXs3VYks5ri6AfgaJpZM4L_dqC>
.
|
I can confirm that this works in PHPExcel library, now will try PHPSpreadsheet |
Works for PHPSpreadsheet as well, Thank you @ankitm123 great job! |
Thanks all for your collaboration. |
Hi,
This has been an issue in PHPExcel and is present in this library also.
Steps to reproduce:
MemoryDrawing
and insert image to a sheetWhat you will see is that if you add the drawing to say coordinates
E2
and then add rows and columns to clone and image will shift toF10
when you look at the original sheet, image also moved toF10
over thereThe text was updated successfully, but these errors were encountered: