-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Read and write hyperlink for drawing image
Fixes #490
- Loading branch information
Showing
9 changed files
with
253 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
use PhpOffice\PhpSpreadsheet\Spreadsheet; | ||
|
||
require __DIR__ . '/../Header.php'; | ||
$inputFileType = 'Xlsx'; | ||
|
||
$helper->log('Start'); | ||
|
||
$spreadsheet = new Spreadsheet(); | ||
|
||
$aSheet = $spreadsheet->getActiveSheet(); | ||
|
||
$gdImage = @imagecreatetruecolor(120, 20); | ||
$textColor = imagecolorallocate($gdImage, 255, 255, 255); | ||
imagestring($gdImage, 1, 5, 5, 'Created with PhpSpreadsheet', $textColor); | ||
|
||
$baseUrl = 'https://phpspreadsheet.readthedocs.io/'; | ||
|
||
$drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing(); | ||
$drawing->setName('In-Memory image 1'); | ||
$drawing->setDescription('In-Memory image 1'); | ||
$drawing->setCoordinates('A1'); | ||
$drawing->setImageResource($gdImage); | ||
$drawing->setRenderingFunction( | ||
\PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing::RENDERING_JPEG | ||
); | ||
$drawing->setMimeType(\PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing::MIMETYPE_DEFAULT); | ||
$drawing->setHeight(36); | ||
$helper->log('Write image'); | ||
|
||
$hyperLink = new \PhpOffice\PhpSpreadsheet\Cell\Hyperlink($baseUrl, 'test image'); | ||
$drawing->setHyperlink($hyperLink); | ||
$helper->log('Write link: ' . $baseUrl); | ||
|
||
$drawing->setWorksheet($aSheet); | ||
|
||
$filename = tempnam(\PhpOffice\PhpSpreadsheet\Shared\File::sysGetTempDir(), 'phpspreadsheet-test'); | ||
|
||
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, $inputFileType); | ||
$writer->save($filename); | ||
|
||
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); | ||
|
||
$reloadedSpreadsheet = $reader->load($filename); | ||
unlink($filename); | ||
|
||
$helper->log('reloaded Spreadsheet'); | ||
|
||
foreach ($reloadedSpreadsheet->getActiveSheet()->getDrawingCollection() as $pDrawing) { | ||
$helper->log('Read link: ' . $pDrawing->getHyperlink()->getUrl()); | ||
} | ||
|
||
$helper->log('end'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
tests/PhpSpreadsheetTests/Functional/DrawingImageHyperlinkTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: yuzhakov | ||
* Date: 08.05.18 | ||
* Time: 12:00. | ||
*/ | ||
|
||
namespace PhpOffice\PhpSpreadsheetTests\Functional; | ||
|
||
use PhpOffice\PhpSpreadsheet\Cell\Hyperlink; | ||
use PhpOffice\PhpSpreadsheet\Spreadsheet; | ||
use PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing; | ||
|
||
class DrawingImageHyperlinkTest extends AbstractFunctional | ||
{ | ||
/** | ||
* @throws \PhpOffice\PhpSpreadsheet\Exception | ||
*/ | ||
public function testDrawingImageHyperlinkTest() | ||
{ | ||
$baseUrl = 'https://github.com/PHPOffice/PhpSpreadsheet'; | ||
$spreadsheet = new Spreadsheet(); | ||
|
||
$aSheet = $spreadsheet->getActiveSheet(); | ||
|
||
$gdImage = @imagecreatetruecolor(120, 20); | ||
$textColor = imagecolorallocate($gdImage, 255, 255, 255); | ||
imagestring($gdImage, 1, 5, 5, 'Created with PhpSpreadsheet', $textColor); | ||
|
||
$drawing = new MemoryDrawing(); | ||
$drawing->setName('In-Memory image 1'); | ||
$drawing->setDescription('In-Memory image 1'); | ||
$drawing->setCoordinates('A1'); | ||
$drawing->setImageResource($gdImage); | ||
$drawing->setRenderingFunction( | ||
MemoryDrawing::RENDERING_JPEG | ||
); | ||
$drawing->setMimeType(MemoryDrawing::MIMETYPE_DEFAULT); | ||
$drawing->setHeight(36); | ||
$hyperLink = new Hyperlink($baseUrl, 'test image'); | ||
$drawing->setHyperlink($hyperLink); | ||
$drawing->setWorksheet($aSheet); | ||
|
||
$reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx'); | ||
|
||
foreach ($reloadedSpreadsheet->getActiveSheet()->getDrawingCollection() as $pDrawing) { | ||
self::assertEquals('https://github.com/PHPOffice/PhpSpreadsheet', $pDrawing->getHyperlink()->getUrl(), 'functional test drawing hyperlink'); | ||
} | ||
} | ||
} |