Skip to content
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

fix warning when open xlsx file with thumbnail #2517

Merged
merged 2 commits into from Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/PhpSpreadsheet/Reader/Xlsx.php
Expand Up @@ -149,6 +149,7 @@ private function loadZipNonamespace(string $filename, string $ns): SimpleXMLElem

private const REL_TO_MAIN = [
Namespaces::PURL_OFFICE_DOCUMENT => Namespaces::PURL_MAIN,
Namespaces::THUMBNAIL => '',
];

private const REL_TO_DRAWING = [
Expand Down
2 changes: 2 additions & 0 deletions src/PhpSpreadsheet/Reader/Xlsx/Namespaces.php
Expand Up @@ -14,6 +14,8 @@ class Namespaces
// This one used in Reader\Xlsx\Properties
const CORE_PROPERTIES2 = 'http://schemas.openxmlformats.org/package/2006/metadata/core-properties';

const THUMBNAIL = 'http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail';

const THEME = 'http://schemas.openxmlformats.org/package/2006/relationships/theme';

const COMPATIBILITY = 'http://schemas.openxmlformats.org/markup-compatibility/2006';
Expand Down
62 changes: 62 additions & 0 deletions tests/PhpSpreadsheetTests/Reader/Xlsx/Issue2516Test.php
@@ -0,0 +1,62 @@
<?php

namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx;

use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
use PHPUnit\Framework\TestCase;

class Issue2516Test extends TestCase
{
/**
* @var string
*/
private static $testbook = 'tests/data/Reader/XLSX/issue.2516b.xlsx';

public function testPreliminaries(): void
{
$file = 'zip://';
$file .= self::$testbook;
$file .= '#docProps/thumbnail.wmf';
$data = file_get_contents($file);

// confirm that file exists
self::assertNotFalse($data, 'thumbnail.wmf not exists');

$file = 'zip://';
$file .= self::$testbook;
$file .= '#_rels/.rels';
$data = file_get_contents($file);
// confirm that file contains expected namespaced xml tag
if ($data === false) {
self::fail('Unable to read file .rels');
} else {
self::assertStringContainsString('Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail" Target="docProps/thumbnail.wmf"', $data);
}
}

public function testIssue2516a(): void
{
$filename = self::$testbook;
$reader = new Xlsx();
$names = $reader->listWorksheetNames($filename);
$expected = ['Sheet1'];
self::assertSame($expected, $names);
}

public function testIssue2516b(): void
{
$filename = self::$testbook;
$reader = new Xlsx();
$infos = $reader->listWorksheetInfo($filename);
$expected = [
[
'worksheetName' => 'Sheet1',
'lastColumnLetter' => 'B',
'lastColumnIndex' => 1,
'totalRows' => '6',
'totalColumns' => 2,
],
];
self::assertSame($expected, $infos);
}
}
Binary file added tests/data/Reader/XLSX/issue.2516b.xlsx
Binary file not shown.