mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-08-31 04:28:51 +00:00
Better Sample File
This commit is contained in:
@@ -84,6 +84,8 @@ $config
|
||||
'method_chaining_indentation' => true,
|
||||
'modernize_strpos' => true,
|
||||
'modernize_types_casting' => true,
|
||||
'modifier_keywords' => ['elements' => ['property', 'method']], // not const
|
||||
|
||||
'multiline_comment_opening_closing' => true,
|
||||
'multiline_whitespace_before_semicolons' => true,
|
||||
'native_constant_invocation' => false, // Micro optimization that look messy
|
||||
@@ -236,7 +238,6 @@ $config
|
||||
'types_spaces' => true,
|
||||
'unary_operator_spaces' => true,
|
||||
'use_arrow_functions' => true,
|
||||
'visibility_required' => ['elements' => ['property', 'method']], // not const
|
||||
'void_return' => true,
|
||||
'whitespace_after_comma_in_array' => true,
|
||||
'yoda_style' => false,
|
||||
|
||||
@@ -1205,9 +1205,10 @@ class Xlsx extends BaseReader
|
||||
$shapes = self::xpathNoFalse($vmlCommentsFile, '//v:shape');
|
||||
foreach ($shapes as $shape) {
|
||||
/** @var SimpleXMLElement $shape */
|
||||
$shape->registerXPathNamespace('v', Namespaces::URN_VML);
|
||||
$shape->registerXPathNamespace('x', Namespaces::URN_VML);
|
||||
$shape->registerXPathNamespace('o', Namespaces::URN_MSOFFICE);
|
||||
$vmlNamespaces = $shape->getNamespaces();
|
||||
$shape->registerXPathNamespace('v', $vmlNamespaces['v'] ?? Namespaces::URN_VML);
|
||||
$shape->registerXPathNamespace('x', $vmlNamespaces['x'] ?? Namespaces::URN_EXCEL);
|
||||
$shape->registerXPathNamespace('o', $vmlNamespaces['o'] ?? Namespaces::URN_MSOFFICE);
|
||||
|
||||
if (isset($shape['style'])) {
|
||||
$style = (string) $shape['style'];
|
||||
@@ -1232,6 +1233,7 @@ class Xlsx extends BaseReader
|
||||
$clientData = $clientData[0];
|
||||
|
||||
if (isset($clientData['ObjectType']) && (string) $clientData['ObjectType'] == 'Note') {
|
||||
$clientData->registerXPathNamespace('x', $vmlNamespaces['x'] ?? Namespaces::URN_EXCEL);
|
||||
$temp = $clientData->xpath('.//x:Row');
|
||||
if (is_array($temp)) {
|
||||
$row = $temp[0];
|
||||
|
||||
@@ -5,13 +5,11 @@ declare(strict_types=1);
|
||||
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader;
|
||||
use PhpOffice\PhpSpreadsheet\Reader\Xlsx\Namespaces as XlsxNamespaces;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use SimpleXMLElement;
|
||||
|
||||
class Issue4505Test extends TestCase
|
||||
{
|
||||
private static string $file = 'tests/data/Reader/XLSX/issue.4505.xlsx';
|
||||
private static string $file = 'tests/data/Reader/XLSX/issue.4505.namespace.xlsx';
|
||||
|
||||
public function testVmlProcessingWithXAndONamespaces(): void
|
||||
{
|
||||
@@ -20,61 +18,24 @@ class Issue4505Test extends TestCase
|
||||
$sheet = $spreadsheet->getActiveSheet();
|
||||
|
||||
$comments = $sheet->getComments();
|
||||
self::assertSame('Sheet1', $sheet->getTitle());
|
||||
|
||||
if (!empty($comments)) {
|
||||
$comment = reset($comments);
|
||||
$comment->getText();
|
||||
}
|
||||
|
||||
self::assertArrayHasKey('A1', $comments);
|
||||
self::assertSame('right', $comments['A1']->getAlignment());
|
||||
self::assertSame("Some User:\nHello", (string) $comments['A1']->getText());
|
||||
$spreadsheet->disconnectWorksheets();
|
||||
}
|
||||
|
||||
public function testVmlFileContainsRequiredNamespaces(): void
|
||||
{
|
||||
$file = 'zip://' . self::$file . '#xl/drawings/vmlDrawing1.vml';
|
||||
$data = file_get_contents($file);
|
||||
$data = (string) file_get_contents($file);
|
||||
|
||||
if ($data === false) {
|
||||
self::markTestSkipped('Test file issue.4505.xlsx not found or VML file missing.');
|
||||
}
|
||||
|
||||
self::assertStringContainsString('<v:shape', $data);
|
||||
self::assertStringContainsString('o:shapelayout', $data);
|
||||
self::assertStringContainsString('x:ClientData', $data);
|
||||
self::assertStringContainsString('o:insetmode', $data);
|
||||
}
|
||||
|
||||
public function testXPathQueriesWithNamespaceRegistration(): void
|
||||
{
|
||||
$vmlContent = '<?xml version="1.0" encoding="UTF-8"?>
|
||||
<v:shape xmlns:v="urn:schemas-microsoft-com:vml"
|
||||
xmlns:x="urn:schemas-microsoft-com:office:excel"
|
||||
xmlns:o="urn:schemas-microsoft-com:office:office">
|
||||
<v:fill o:relid="rId1" o:title="Test Image"/>
|
||||
<x:ClientData ObjectType="Note">
|
||||
<x:Row>5</x:Row>
|
||||
<x:Column>2</x:Column>
|
||||
<x:TextHAlign>left</x:TextHAlign>
|
||||
</x:ClientData>
|
||||
</v:shape>';
|
||||
|
||||
$shape = new SimpleXMLElement($vmlContent);
|
||||
|
||||
$shape->registerXPathNamespace('v', XlsxNamespaces::URN_VML);
|
||||
$shape->registerXPathNamespace('x', XlsxNamespaces::URN_VML);
|
||||
$shape->registerXPathNamespace('o', XlsxNamespaces::URN_MSOFFICE);
|
||||
|
||||
$clientData = $shape->xpath('.//x:ClientData');
|
||||
self::assertNotEmpty($clientData, 'XPath with x: prefix works with namespace registration');
|
||||
|
||||
$relid = $shape->xpath('.//v:fill/@o:relid');
|
||||
self::assertNotEmpty($relid, 'XPath with o: prefix works with namespace registration');
|
||||
|
||||
$row = $clientData[0]->xpath('.//x:Row');
|
||||
self::assertNotEmpty($row, 'Can access nested x: elements');
|
||||
self::assertEquals('5', (string) $row[0], 'Row value is correct');
|
||||
|
||||
self::assertEquals('rId1', (string) $relid[0], 'RelId value is correct');
|
||||
self::assertStringContainsString('<ns1:shape ', $data); // usually v:shape
|
||||
self::assertStringContainsString('<ns3:shapelayout ns1:ext="edit">', $data); // usually o:shapelayout v:ext
|
||||
self::assertStringContainsString('<ns2:ClientData ObjectType="Note">', $data); // usually x:ClientData
|
||||
self::assertStringContainsString('ns3:insetmode', $data); // usually o:insetmode
|
||||
self::assertStringContainsString(
|
||||
'<ns2:TextHAlign>Right</ns2:TextHAlign>', // usually x:TextHAlign
|
||||
$data
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user