repo stringlengths 7 63 | file_url stringlengths 81 284 | file_path stringlengths 5 200 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 15:02:33 2026-01-05 05:24:06 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Xml/Issue4448Test.php | tests/PhpSpreadsheetTests/Reader/Xml/Issue4448Test.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xml;
use PhpOffice\PhpSpreadsheet\Reader\Xml;
use PHPUnit\Framework\TestCase;
class Issue4448Test extends TestCase
{
private static string $testbook = 'tests/data/Reader/Xml/issue.4448.xml';
public function testIndent(): void
{
$reader = new Xml();
$spreadsheet = $reader->load(self::$testbook);
$sheet = $spreadsheet->getActiveSheet();
self::assertSame(
5,
$sheet->getStyle('A2')
->getAlignment()
->getIndent()
);
self::assertSame(
0,
$sheet->getStyle('A1')
->getAlignment()
->getIndent()
);
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Xml/ArrayFormulaTest.php | tests/PhpSpreadsheetTests/Reader/Xml/ArrayFormulaTest.php | <?php
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xml;
use PhpOffice\PhpSpreadsheet\Cell\DataType;
use PhpOffice\PhpSpreadsheet\Reader\Xml;
use PHPUnit\Framework\TestCase;
class ArrayFormulaTest extends TestCase
{
public function testArrayFormulaReader(): void
{
$filename = 'tests/data/Reader/Xml/ArrayFormula.xml';
$reader = new Xml();
$spreadsheet = $reader->load($filename);
$sheet = $spreadsheet->getActiveSheet();
self::assertSame(DataType::TYPE_FORMULA, $sheet->getCell('B1')->getDataType());
self::assertSame(['t' => 'array', 'ref' => 'B1:B3'], $sheet->getCell('B1')->getFormulaAttributes());
self::assertSame('=CONCATENATE(A1:A3,"-",C1:C3)', strtoupper($sheet->getCell('B1')->getValueString()));
self::assertSame('a-1', $sheet->getCell('B1')->getOldCalculatedValue());
self::assertSame('b-2', $sheet->getCell('B2')->getValue());
self::assertSame('c-3', $sheet->getCell('B3')->getValue());
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Xml/PageSetupTest.php | tests/PhpSpreadsheetTests/Reader/Xml/PageSetupTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xml;
use PhpOffice\PhpSpreadsheet\Reader\Xml;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup;
use PHPUnit\Framework\TestCase;
class PageSetupTest extends TestCase
{
private const MARGIN_PRECISION = 0.000001;
private const MARGIN_UNIT_CONVERSION = 2.54; // Inches to cm
private ?Spreadsheet $spreadsheet = null;
private string $filename = 'tests/data/Reader/Xml/PageSetup.xml';
protected function tearDown(): void
{
if ($this->spreadsheet !== null) {
$this->spreadsheet->disconnectWorksheets();
$this->spreadsheet = null;
}
}
public function testPageSetup(): void
{
$reader = new Xml();
$this->spreadsheet = $reader->load($this->filename);
$assertions = $this->pageSetupAssertions();
$sheetCount = 0;
foreach ($this->spreadsheet->getAllSheets() as $worksheet) {
if (!array_key_exists($worksheet->getTitle(), $assertions)) {
self::fail('Unexpected worksheet ' . $worksheet->getTitle());
}
++$sheetCount;
$sheetAssertions = $assertions[$worksheet->getTitle()];
foreach ($sheetAssertions as $test => $expectedResult) {
$testMethodName = 'get' . ucfirst($test);
$actualResult = $worksheet->getPageSetup()->$testMethodName();
self::assertSame(
$expectedResult,
$actualResult,
"Failed assertion for Worksheet '{$worksheet->getTitle()}' {$test}"
);
}
}
self::assertCount($sheetCount, $assertions);
}
public function testPageMargins(): void
{
$reader = new Xml();
$this->spreadsheet = $reader->load($this->filename);
$assertions = $this->pageMarginAssertions();
$sheetCount = 0;
foreach ($this->spreadsheet->getAllSheets() as $worksheet) {
if (!array_key_exists($worksheet->getTitle(), $assertions)) {
self::fail('Unexpected worksheet ' . $worksheet->getTitle());
}
++$sheetCount;
$sheetAssertions = $assertions[$worksheet->getTitle()];
foreach ($sheetAssertions as $test => $expectedResult) {
$testMethodName = 'get' . ucfirst($test);
$actualResult = $worksheet->getPageMargins()->$testMethodName();
self::assertEqualsWithDelta(
$expectedResult,
$actualResult,
self::MARGIN_PRECISION,
"Failed assertion for Worksheet '{$worksheet->getTitle()}' {$test} margin"
);
}
}
self::assertCount($sheetCount, $assertions);
}
/** @return array<string, array{orientation: string, scale: int, horizontalCentered: bool, verticalCentered: bool, pageOrder: string}> */
private function pageSetupAssertions(): array
{
return [
'Sheet1' => [
'orientation' => PageSetup::ORIENTATION_PORTRAIT,
'scale' => 75,
'horizontalCentered' => true,
'verticalCentered' => false,
'pageOrder' => PageSetup::PAGEORDER_DOWN_THEN_OVER,
],
'Sheet2' => [
'orientation' => PageSetup::ORIENTATION_LANDSCAPE,
'scale' => 100,
'horizontalCentered' => false,
'verticalCentered' => true,
'pageOrder' => PageSetup::PAGEORDER_OVER_THEN_DOWN,
],
'Sheet3' => [
'orientation' => PageSetup::ORIENTATION_PORTRAIT,
'scale' => 90,
'horizontalCentered' => true,
'verticalCentered' => true,
'pageOrder' => PageSetup::PAGEORDER_DOWN_THEN_OVER,
],
'Sheet4' => [
// Default Settings
'orientation' => PageSetup::ORIENTATION_DEFAULT,
'scale' => 100,
'horizontalCentered' => false,
'verticalCentered' => false,
'pageOrder' => PageSetup::PAGEORDER_DOWN_THEN_OVER,
],
];
}
/** @return array<string, float[]> */
private function pageMarginAssertions(): array
{
return [
'Sheet1' => [
// Here the values are in cm, so we convert to inches for comparison with internal uom
'top' => 2.4 / self::MARGIN_UNIT_CONVERSION,
'header' => 0.8 / self::MARGIN_UNIT_CONVERSION,
'left' => 1.3 / self::MARGIN_UNIT_CONVERSION,
'right' => 1.3 / self::MARGIN_UNIT_CONVERSION,
'bottom' => 1.9 / self::MARGIN_UNIT_CONVERSION,
'footer' => 0.8 / self::MARGIN_UNIT_CONVERSION,
],
'Sheet2' => [
// Here the values are in cm, so we convert to inches for comparison with internal uom
'top' => 1.9 / self::MARGIN_UNIT_CONVERSION,
'header' => 0.8 / self::MARGIN_UNIT_CONVERSION,
'left' => 1.8 / self::MARGIN_UNIT_CONVERSION,
'right' => 1.8 / self::MARGIN_UNIT_CONVERSION,
'bottom' => 1.9 / self::MARGIN_UNIT_CONVERSION,
'footer' => 0.8 / self::MARGIN_UNIT_CONVERSION,
],
'Sheet3' => [
// Here the values are in cm, so we convert to inches for comparison with internal uom
'top' => 2.4 / self::MARGIN_UNIT_CONVERSION,
'header' => 1.3 / self::MARGIN_UNIT_CONVERSION,
'left' => 1.8 / self::MARGIN_UNIT_CONVERSION,
'right' => 1.8 / self::MARGIN_UNIT_CONVERSION,
'bottom' => 2.4 / self::MARGIN_UNIT_CONVERSION,
'footer' => 1.3 / self::MARGIN_UNIT_CONVERSION,
],
'Sheet4' => [
// Default Settings (already in inches for comparison)
'top' => 0.75,
'header' => 0.3,
'left' => 0.7,
'right' => 0.7,
'bottom' => 0.75,
'footer' => 0.3,
],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Xml/XmlStylesTest.php | tests/PhpSpreadsheetTests/Reader/Xml/XmlStylesTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xml;
use PhpOffice\PhpSpreadsheet\Reader\Xml;
use PhpOffice\PhpSpreadsheet\Style\Alignment;
use PhpOffice\PhpSpreadsheet\Style\Border;
use PhpOffice\PhpSpreadsheet\Style\Borders;
use PhpOffice\PhpSpreadsheet\Style\Color;
use PhpOffice\PhpSpreadsheet\Style\Fill;
use PhpOffice\PhpSpreadsheet\Style\Font;
use PHPUnit\Framework\TestCase;
class XmlStylesTest extends TestCase
{
public function testBorders(): void
{
$filename = __DIR__
. '/../../../..'
. '/samples/templates/excel2003.xml';
$reader = new Xml();
$spreadsheet = $reader->load($filename);
$sheet = $spreadsheet->getSheet(0);
self::assertEquals(Border::BORDER_MEDIUM, $sheet->getCell('C10')->getStyle()->getBorders()->getTop()->getBorderStyle());
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C10')->getStyle()->getBorders()->getRight()->getBorderStyle());
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C10')->getStyle()->getBorders()->getBottom()->getBorderStyle());
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C10')->getStyle()->getBorders()->getLeft()->getBorderStyle());
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C12')->getStyle()->getBorders()->getTop()->getBorderStyle());
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C12')->getStyle()->getBorders()->getRight()->getBorderStyle());
self::assertEquals(Border::BORDER_MEDIUM, $sheet->getCell('C12')->getStyle()->getBorders()->getBottom()->getBorderStyle());
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C12')->getStyle()->getBorders()->getLeft()->getBorderStyle());
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C14')->getStyle()->getBorders()->getTop()->getBorderStyle());
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C14')->getStyle()->getBorders()->getRight()->getBorderStyle());
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C14')->getStyle()->getBorders()->getBottom()->getBorderStyle());
self::assertEquals(Border::BORDER_MEDIUM, $sheet->getCell('C14')->getStyle()->getBorders()->getLeft()->getBorderStyle());
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C16')->getStyle()->getBorders()->getTop()->getBorderStyle());
self::assertEquals(Border::BORDER_MEDIUM, $sheet->getCell('C16')->getStyle()->getBorders()->getRight()->getBorderStyle());
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C16')->getStyle()->getBorders()->getBottom()->getBorderStyle());
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C16')->getStyle()->getBorders()->getLeft()->getBorderStyle());
self::assertEquals(Border::BORDER_THICK, $sheet->getCell('C18')->getStyle()->getBorders()->getTop()->getBorderStyle());
self::assertEquals(Color::COLOR_RED, $sheet->getCell('C18')->getStyle()->getBorders()->getTop()->getColor()->getARGB());
self::assertEquals(Border::BORDER_THICK, $sheet->getCell('C18')->getStyle()->getBorders()->getRight()->getBorderStyle());
self::assertEquals(Color::COLOR_YELLOW, $sheet->getCell('C18')->getStyle()->getBorders()->getRight()->getColor()->getARGB());
self::assertEquals(Border::BORDER_THICK, $sheet->getCell('C18')->getStyle()->getBorders()->getRight()->getBorderStyle());
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C18')->getStyle()->getBorders()->getBottom()->getBorderStyle());
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C18')->getStyle()->getBorders()->getLeft()->getBorderStyle());
self::assertEquals(Borders::DIAGONAL_BOTH, $sheet->getCell('E18')->getStyle()->getBorders()->getDiagonalDirection());
self::assertEquals(Borders::DIAGONAL_DOWN, $sheet->getCell('I18')->getStyle()->getBorders()->getDiagonalDirection());
self::assertEquals(Borders::DIAGONAL_UP, $sheet->getCell('J18')->getStyle()->getBorders()->getDiagonalDirection());
$spreadsheet->disconnectWorksheets();
}
public function testFont(): void
{
$filename = __DIR__
. '/../../../..'
. '/samples/templates/excel2003.xml';
$reader = new Xml();
$spreadsheet = $reader->load($filename);
$sheet = $spreadsheet->getSheet(0);
self::assertEquals('FFFF0000', $sheet->getCell('A1')->getStyle()->getFont()->getColor()->getARGB());
self::assertEquals(Font::UNDERLINE_SINGLE, $sheet->getCell('A3')->getStyle()->getFont()->getUnderline());
self::assertTrue($sheet->getCell('E1')->getStyle()->getFont()->getBold());
self::assertTrue($sheet->getCell('E1')->getStyle()->getFont()->getItalic());
self::assertFalse($sheet->getCell('E2')->getStyle()->getFont()->getBold());
self::assertFalse($sheet->getCell('E2')->getStyle()->getFont()->getItalic());
self::assertEquals(Font::UNDERLINE_NONE, $sheet->getCell('E2')->getStyle()->getFont()->getUnderline());
self::assertTrue($sheet->getCell('E3')->getStyle()->getFont()->getBold());
self::assertFalse($sheet->getCell('E3')->getStyle()->getFont()->getItalic());
self::assertEquals(Font::UNDERLINE_NONE, $sheet->getCell('E3')->getStyle()->getFont()->getUnderline());
self::assertFalse($sheet->getCell('E4')->getStyle()->getFont()->getBold());
self::assertTrue($sheet->getCell('E4')->getStyle()->getFont()->getItalic());
self::assertEquals(Font::UNDERLINE_NONE, $sheet->getCell('E4')->getStyle()->getFont()->getUnderline());
self::assertTrue($sheet->getCell('F1')->getStyle()->getFont()->getBold());
self::assertFalse($sheet->getCell('F1')->getStyle()->getFont()->getItalic());
self::assertEquals(Font::UNDERLINE_NONE, $sheet->getCell('F1')->getStyle()->getFont()->getUnderline());
self::assertFalse($sheet->getCell('F2')->getStyle()->getFont()->getBold());
self::assertFalse($sheet->getCell('F2')->getStyle()->getFont()->getItalic());
self::assertEquals(Font::UNDERLINE_NONE, $sheet->getCell('F2')->getStyle()->getFont()->getUnderline());
self::assertTrue($sheet->getCell('F3')->getStyle()->getFont()->getBold());
self::assertTrue($sheet->getCell('F3')->getStyle()->getFont()->getItalic());
self::assertEquals(Font::UNDERLINE_NONE, $sheet->getCell('F3')->getStyle()->getFont()->getUnderline());
self::assertFalse($sheet->getCell('F4')->getStyle()->getFont()->getBold());
self::assertFalse($sheet->getCell('F4')->getStyle()->getFont()->getItalic());
self::assertEquals(Font::UNDERLINE_NONE, $sheet->getCell('F4')->getStyle()->getFont()->getUnderline());
self::assertEquals(45, $sheet->getCell('E22')->getStyle()->getAlignment()->getTextRotation());
self::assertEquals(-90, $sheet->getCell('G22')->getStyle()->getAlignment()->getTextRotation());
self::assertEquals(Border::BORDER_DOUBLE, $sheet->getCell('N13')->getStyle()->getBorders()->getBottom()->getBorderStyle());
self::assertEquals(Font::UNDERLINE_DOUBLE, $sheet->getCell('A24')->getStyle()->getFont()->getUnderline());
self::assertTrue($sheet->getCell('B23')->getStyle()->getFont()->getSubScript());
self::assertTrue($sheet->getCell('B24')->getStyle()->getFont()->getSuperScript());
$spreadsheet->disconnectWorksheets();
}
public function testFill(): void
{
$filename = __DIR__
. '/../../../..'
. '/samples/templates/excel2003.xml';
$reader = new Xml();
$spreadsheet = $reader->load($filename);
$sheet = $spreadsheet->getSheet(0);
self::assertEquals(Fill::FILL_PATTERN_DARKHORIZONTAL, $sheet->getCell('K19')->getStyle()->getFill()->getFillType());
self::assertEquals('FF00CCFF', $sheet->getCell('K19')->getStyle()->getFill()->getEndColor()->getARGB());
self::assertEquals(Color::COLOR_BLUE, $sheet->getCell('K19')->getStyle()->getFill()->getStartColor()->getARGB());
self::assertEquals(Fill::FILL_PATTERN_GRAY0625, $sheet->getCell('L19')->getStyle()->getFill()->getFillType());
self::assertEquals(Color::COLOR_RED, $sheet->getCell('L19')->getStyle()->getFill()->getEndColor()->getARGB());
self::assertEquals(Color::COLOR_YELLOW, $sheet->getCell('L19')->getStyle()->getFill()->getStartColor()->getARGB());
self::assertEquals(Fill::FILL_SOLID, $sheet->getCell('K3')->getStyle()->getFill()->getFillType());
self::assertEquals(Color::COLOR_RED, $sheet->getCell('K3')->getStyle()->getFill()->getEndColor()->getARGB());
$spreadsheet->disconnectWorksheets();
}
public function testAlignment(): void
{
$filename = __DIR__
. '/../../../..'
. '/samples/templates/excel2003.xml';
$reader = new Xml();
$spreadsheet = $reader->load($filename);
$sheet = $spreadsheet->getSheet(0);
self::assertEquals(45, $sheet->getCell('E22')->getStyle()->getAlignment()->getTextRotation());
self::assertEquals(-90, $sheet->getCell('G22')->getStyle()->getAlignment()->getTextRotation());
self::assertEquals(Alignment::HORIZONTAL_CENTER, $sheet->getCell('N2')->getStyle()->getAlignment()->getHorizontal());
self::assertEquals(Alignment::HORIZONTAL_RIGHT, $sheet->getCell('N3')->getStyle()->getAlignment()->getHorizontal());
self::assertEquals(Alignment::VERTICAL_TOP, $sheet->getCell('K19')->getStyle()->getAlignment()->getVertical());
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Xml/XmlTopLeftTest.php | tests/PhpSpreadsheetTests/Reader/Xml/XmlTopLeftTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xml;
use PhpOffice\PhpSpreadsheet\Reader\Xml;
use PHPUnit\Framework\TestCase;
class XmlTopLeftTest extends TestCase
{
public function testTopLeft(): void
{
$xmldata = <<< 'EOT'
<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40">
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Protection x:HideFormula="1" ss:Protected="1"/>
</Style>
<Style ss:ID="visible">
<Protection x:HideFormula="0" ss:Protected="1"/>
</Style>
<Style ss:ID="writable">
<Protection x:HideFormula="1" ss:Protected="0"/>
</Style>
</Styles>
<Worksheet ss:Name="sheet 1" ss:Protected="1">
<ss:Table>
<ss:Row>
<ss:Cell>
<ss:Data ss:Type="String">1.1</ss:Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:Type="String">1.2</ss:Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:Type="String">1.3</ss:Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:Type="String">1.4</ss:Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:Type="String">1.5</ss:Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:Type="String">1.6</ss:Data>
</ss:Cell>
</ss:Row>
<ss:Row>
<ss:Cell>
<ss:Data ss:Type="String">2.1</ss:Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:Type="String">2.2 (top-left cell)</ss:Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:Type="String">2.3</ss:Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:Type="String">2.4</ss:Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:Type="String">2.5</ss:Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:Type="String">2.6</ss:Data>
</ss:Cell>
</ss:Row>
<ss:Row>
<ss:Cell>
<ss:Data ss:Type="String">3.1</ss:Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:Type="String">3.2</ss:Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:Type="String">3.3</ss:Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:Type="String">3.4</ss:Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:Type="String">3.5</ss:Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:Type="String">3.6</ss:Data>
</ss:Cell>
</ss:Row>
</ss:Table>
<WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
<TopRowVisible>1</TopRowVisible>
<LeftColumnVisible>1</LeftColumnVisible>
</WorksheetOptions>
</Worksheet>
</Workbook>
EOT;
$reader = new Xml();
$spreadsheet = $reader->loadSpreadsheetFromString($xmldata);
self::assertEquals(1, $spreadsheet->getSheetCount());
$sheet = $spreadsheet->getActiveSheet();
self::assertEquals('sheet 1', $sheet->getTitle());
self::assertEquals('B2', $sheet->getTopLeftCell());
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Xml/XmlPropertiesTest.php | tests/PhpSpreadsheetTests/Reader/Xml/XmlPropertiesTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xml;
use DateTimeImmutable;
use PhpOffice\PhpSpreadsheet\Reader\Xml;
use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional;
class XmlPropertiesTest extends AbstractFunctional
{
private string $filename = 'tests/data/Reader/Xml/hyperlinkbase.xml';
public function testProperties(): void
{
$reader = new Xml();
$spreadsheet = $reader->load($this->filename);
$properties = $spreadsheet->getProperties();
self::assertSame('title', $properties->getTitle());
self::assertSame('topic', $properties->getSubject());
self::assertSame('author', $properties->getCreator());
self::assertSame('keyword1, keyword2', $properties->getKeywords());
self::assertSame('no comment', $properties->getDescription());
self::assertSame('last author', $properties->getLastModifiedBy());
$expected = self::timestampToInt('2023-05-18T11:21:43Z');
self::assertEquals($expected, $properties->getCreated());
$expected = self::timestampToInt('2023-05-18T11:30:00Z');
self::assertEquals($expected, $properties->getModified());
self::assertSame('category', $properties->getCategory());
self::assertSame('manager', $properties->getManager());
self::assertSame('company', $properties->getCompany());
self::assertSame('https://phpspreadsheet.readthedocs.io/en/latest/', $properties->getHyperlinkBase());
self::assertSame('TheString', $properties->getCustomPropertyValue('StringProperty'));
self::assertSame(12345, $properties->getCustomPropertyValue('NumberProperty'));
$expected = self::timestampToInt('2023-05-18T10:00:00Z');
self::assertEquals($expected, $properties->getCustomPropertyValue('DateProperty'));
$expected = self::timestampToInt('2023-05-19T11:00:00Z');
self::assertEquals($expected, $properties->getCustomPropertyValue('DateProperty2'));
self::assertTrue($properties->getCustomPropertyValue('BooleanPropertyTrue'));
self::assertFalse($properties->getCustomPropertyValue('BooleanPropertyFalse'));
self::assertEqualsWithDelta(1.2345, $properties->getCustomPropertyValue('FloatProperty'), 1E-8);
$sheet = $spreadsheet->getActiveSheet();
// Note that relative links don't actually work in XML format.
// It will, however, work just fine in the Xlsx and Html copies.
$hyperlink = $sheet->getCell('A1')->getHyperlink();
self::assertSame('references/features-cross-reference/', $hyperlink->getUrl());
// Same comment as for cell above.
self::assertSame('topics/accessing-cells/', $sheet->getCell('A2')->getCalculatedValue());
// No problem for absolute links.
$hyperlink = $sheet->getCell('A3')->getHyperlink();
self::assertSame('https://www.google.com/', $hyperlink->getUrl());
self::assertSame('https://www.yahoo.com', $sheet->getCell('A4')->getCalculatedValue());
$reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx');
$spreadsheet->disconnectWorksheets();
$properties = $reloadedSpreadsheet->getProperties();
self::assertSame('title', $properties->getTitle());
self::assertSame('topic', $properties->getSubject());
self::assertSame('author', $properties->getCreator());
self::assertSame('keyword1, keyword2', $properties->getKeywords());
self::assertSame('no comment', $properties->getDescription());
self::assertSame('last author', $properties->getLastModifiedBy());
$expected = self::timestampToInt('2023-05-18T11:21:43Z');
self::assertEquals($expected, $properties->getCreated());
$expected = self::timestampToInt('2023-05-18T11:30:00Z');
self::assertEquals($expected, $properties->getModified());
self::assertSame('category', $properties->getCategory());
self::assertSame('manager', $properties->getManager());
self::assertSame('company', $properties->getCompany());
self::assertSame('https://phpspreadsheet.readthedocs.io/en/latest/', $properties->getHyperlinkBase());
self::assertSame('TheString', $properties->getCustomPropertyValue('StringProperty'));
self::assertSame(12345, $properties->getCustomPropertyValue('NumberProperty'));
// Note that Xlsx will ignore the time part when displaying
// the property.
$expected = self::timestampToInt('2023-05-18T10:00:00Z');
self::assertEquals($expected, $properties->getCustomPropertyValue('DateProperty'));
$expected = self::timestampToInt('2023-05-19T11:00:00Z');
self::assertEquals($expected, $properties->getCustomPropertyValue('DateProperty2'));
self::assertTrue($properties->getCustomPropertyValue('BooleanPropertyTrue'));
self::assertFalse($properties->getCustomPropertyValue('BooleanPropertyFalse'));
self::assertEqualsWithDelta(1.2345, $properties->getCustomPropertyValue('FloatProperty'), 1E-8);
$sheet = $reloadedSpreadsheet->getActiveSheet();
// Note that relative links don't actually work in XML format.
// It will, however, work just fine in the Xlsx and Html copies.
$hyperlink = $sheet->getCell('A1')->getHyperlink();
self::assertSame('references/features-cross-reference/', $hyperlink->getUrl());
// Same comment as for cell above.
self::assertSame('topics/accessing-cells/', $sheet->getCell('A2')->getCalculatedValue());
// No problem for absolute links.
$hyperlink = $sheet->getCell('A3')->getHyperlink();
self::assertSame('https://www.google.com/', $hyperlink->getUrl());
self::assertSame('https://www.yahoo.com', $sheet->getCell('A4')->getCalculatedValue());
$reloadedSpreadsheet->disconnectWorksheets();
}
public function testPropertiesHtml(): void
{
$reader = new Xml();
$spreadsheet = $reader->load($this->filename);
$reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Html');
$spreadsheet->disconnectWorksheets();
$properties = $reloadedSpreadsheet->getProperties();
self::assertSame('https://phpspreadsheet.readthedocs.io/en/latest/', $properties->getHyperlinkBase());
self::assertSame('title', $properties->getTitle());
self::assertSame('topic', $properties->getSubject());
self::assertSame('author', $properties->getCreator());
self::assertSame('keyword1, keyword2', $properties->getKeywords());
self::assertSame('no comment', $properties->getDescription());
self::assertSame('last author', $properties->getLastModifiedBy());
$expected = self::timestampToInt('2023-05-18T11:21:43Z');
self::assertEquals($expected, $properties->getCreated());
$expected = self::timestampToInt('2023-05-18T11:30:00Z');
self::assertEquals($expected, $properties->getModified());
self::assertSame('category', $properties->getCategory());
self::assertSame('manager', $properties->getManager());
self::assertSame('company', $properties->getCompany());
self::assertSame('TheString', $properties->getCustomPropertyValue('StringProperty'));
self::assertSame(12345, $properties->getCustomPropertyValue('NumberProperty'));
$expected = self::timestampToInt('2023-05-18T10:00:00Z');
self::assertEquals($expected, $properties->getCustomPropertyValue('DateProperty'));
$expected = self::timestampToInt('2023-05-19T11:00:00Z');
self::assertEquals($expected, $properties->getCustomPropertyValue('DateProperty2'));
self::assertTrue($properties->getCustomPropertyValue('BooleanPropertyTrue'));
self::assertFalse($properties->getCustomPropertyValue('BooleanPropertyFalse'));
self::assertEqualsWithDelta(1.2345, $properties->getCustomPropertyValue('FloatProperty'), 1E-8);
$sheet = $reloadedSpreadsheet->getActiveSheet();
// Note that relative links don't actually work in XML format.
// It will, however, work just fine in the Xlsx and Html copies.
$hyperlink = $sheet->getCell('A1')->getHyperlink();
self::assertSame('references/features-cross-reference/', $hyperlink->getUrl());
// Same comment as for cell above.
self::assertSame('topics/accessing-cells/', $sheet->getCell('A2')->getCalculatedValue());
// No problem for absolute links.
$hyperlink = $sheet->getCell('A3')->getHyperlink();
self::assertSame('https://www.google.com/', $hyperlink->getUrl());
self::assertSame('https://www.yahoo.com', $sheet->getCell('A4')->getCalculatedValue());
$reloadedSpreadsheet->disconnectWorksheets();
}
public function testHyperlinksXls(): void
{
$reader = new Xml();
$spreadsheet = $reader->load($this->filename);
$reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xls');
$spreadsheet->disconnectWorksheets();
$sheet = $reloadedSpreadsheet->getActiveSheet();
// Note that relative links don't actually work in XML format.
// However, Xls Writer will convert relative to absolute.
$hyperlink = $sheet->getCell('A1')->getHyperlink();
self::assertSame('https://phpspreadsheet.readthedocs.io/en/latest/references/features-cross-reference/', $hyperlink->getUrl());
// Xls writer does not get involved in function call.
// However, hyperlink does get updated somewhere.
//self::assertSame('topics/accessing-cells/', $sheet->getCell('A2')->getCalculatedValue());
$hyperlink = $sheet->getCell('A2')->getHyperlink();
self::assertSame('https://phpspreadsheet.readthedocs.io/en/latest/topics/accessing-cells/', $hyperlink->getUrl());
// No problem for absolute links.
$hyperlink = $sheet->getCell('A3')->getHyperlink();
self::assertSame('https://www.google.com/', $hyperlink->getUrl());
self::assertSame('https://www.yahoo.com', $sheet->getCell('A4')->getCalculatedValue());
$reloadedSpreadsheet->disconnectWorksheets();
}
private static function timestampToInt(string $timestamp): string
{
$dto = new DateTimeImmutable($timestamp);
return $dto->format('U');
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Xml/XmlActiveSheetTest.php | tests/PhpSpreadsheetTests/Reader/Xml/XmlActiveSheetTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xml;
use PhpOffice\PhpSpreadsheet\Reader\Xml;
use PHPUnit\Framework\TestCase;
class XmlActiveSheetTest extends TestCase
{
public function testActiveSheet(): void
{
$xmldata = <<< 'EOT'
<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
<Version>16.00</Version>
</DocumentProperties>
<OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">
<AllowPNG/>
</OfficeDocumentSettings>
<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
<WindowHeight>6820</WindowHeight>
<WindowWidth>19200</WindowWidth>
<WindowTopX>32767</WindowTopX>
<WindowTopY>32767</WindowTopY>
<ActiveSheet>1</ActiveSheet>
<ProtectStructure>False</ProtectStructure>
<ProtectWindows>False</ProtectWindows>
</ExcelWorkbook>
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Bottom"/>
<Borders/>
<Font ss:FontName="Calibri" x:Family="Swiss" ss:Size="11" ss:Color="#000000"/>
<Interior/>
<NumberFormat/>
<Protection/>
</Style>
</Styles>
<Worksheet ss:Name="sheet 1">
<Table ss:ExpandedColumnCount="1" ss:ExpandedRowCount="1" x:FullColumns="1"
x:FullRows="1" ss:DefaultRowHeight="14.5">
<Row>
<Cell><Data ss:Type="String">Sheet 1</Data></Cell>
</Row>
</Table>
<WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
<ProtectObjects>False</ProtectObjects>
<ProtectScenarios>False</ProtectScenarios>
</WorksheetOptions>
</Worksheet>
<Worksheet ss:Name="sheet 2">
<Table ss:ExpandedColumnCount="1" ss:ExpandedRowCount="1" x:FullColumns="1"
x:FullRows="1" ss:DefaultRowHeight="14.5">
<Row>
<Cell><Data ss:Type="String">Sheet 2</Data></Cell>
</Row>
</Table>
<WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
<Selected/>
<Panes>
<Pane>
<Number>3</Number>
<ActiveRow>2</ActiveRow>
<ActiveCol>2</ActiveCol>
</Pane>
</Panes>
<ProtectObjects>False</ProtectObjects>
<ProtectScenarios>False</ProtectScenarios>
</WorksheetOptions>
</Worksheet>
<Worksheet ss:Name="sheet 3">
<Table ss:ExpandedColumnCount="1" ss:ExpandedRowCount="1" x:FullColumns="1"
x:FullRows="1" ss:DefaultRowHeight="14.5">
<Row>
<Cell><Data ss:Type="String">Sheet 3</Data></Cell>
</Row>
</Table>
<WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
<PageSetup>
<Header x:Margin="0.3"/>
<Footer x:Margin="0.3"/>
<PageMargins x:Bottom="0.75" x:Left="0.7" x:Right="0.7" x:Top="0.75"/>
</PageSetup>
<Panes>
<Pane>
<Number>3</Number>
<ActiveRow>3</ActiveRow>
<ActiveCol>2</ActiveCol>
<RangeSelection>R4C3:R4C4</RangeSelection>
</Pane>
</Panes>
<ProtectObjects>False</ProtectObjects>
<ProtectScenarios>False</ProtectScenarios>
</WorksheetOptions>
</Worksheet>
</Workbook>
EOT;
$reader = new Xml();
$spreadsheet = $reader->loadSpreadsheetFromString($xmldata);
self::assertEquals(3, $spreadsheet->getSheetCount());
$sheet = $spreadsheet->getActiveSheet();
self::assertSame('sheet 2', $sheet->getTitle());
self::assertSame('C3', $sheet->getSelectedCells());
$sheet = $spreadsheet->getSheetByNameOrThrow('sheet 3');
self::assertSame('C4:D4', $sheet->getSelectedCells());
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Xml/XmlStyleCoverageTest.php | tests/PhpSpreadsheetTests/Reader/Xml/XmlStyleCoverageTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xml;
use PhpOffice\PhpSpreadsheet\Reader\Xml;
use PhpOffice\PhpSpreadsheet\Style\Border;
use PhpOffice\PhpSpreadsheet\Style\Fill;
use PHPUnit\Framework\TestCase;
class XmlStyleCoverageTest extends TestCase
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerBorderStyle')]
public function testBorderStyle(string $style, string $expectedResult): void
{
$styles = Xml::XmlMappings();
/** @var string[] */
$borders = $styles['borderStyle'];
self::assertEquals($expectedResult, $borders[$style]);
}
public function testBorderStyleCoverage(): void
{
$styles = Xml::XmlMappings();
/** @var mixed[] */
$expected = $styles['borderStyle'];
$covered = [];
foreach ($expected as $key => $val) {
$covered[$key] = 0;
}
$tests = $this->providerBorderStyle();
foreach ($tests as $test) {
/** @var string[] $test */
$covered[$test[0]] = 1;
}
foreach ($covered as $key => $val) {
self::assertEquals(1, $val, "Borderstyle $key not tested");
}
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerfillType')]
public function testFillType(string $style, string $expectedResult): void
{
$styles = Xml::xmlMappings();
/** @var string[] */
$borders = $styles['fillType'];
self::assertEquals($expectedResult, $borders[$style]);
}
public function testFillTypeCoverage(): void
{
$styles = Xml::XmlMappings();
/** @var string[] */
$expected = $styles['fillType'];
$covered = [];
foreach ($expected as $key => $val) {
$covered[$key] = 0;
}
$tests = $this->providerfillType();
foreach ($tests as $test) {
/** @var string[] $test */
$covered[$test[0]] = 1;
}
foreach ($covered as $key => $val) {
self::assertEquals(1, $val, "fillType $key not tested");
}
}
public static function providerBorderStyle(): array
{
return [
['continuous', Border::BORDER_HAIR],
['dash', Border::BORDER_DASHED],
['dashdot', Border::BORDER_DASHDOT],
['dashdotdot', Border::BORDER_DASHDOTDOT],
['dot', Border::BORDER_DOTTED],
['double', Border::BORDER_DOUBLE],
['0continuous', Border::BORDER_HAIR],
['0dash', Border::BORDER_DASHED],
['0dashdot', Border::BORDER_DASHDOT],
['0dashdotdot', Border::BORDER_DASHDOTDOT],
['0dot', Border::BORDER_DOTTED],
['0double', Border::BORDER_DOUBLE],
['1continuous', Border::BORDER_THIN],
['1dash', Border::BORDER_DASHED],
['1dashdot', Border::BORDER_DASHDOT],
['1dashdotdot', Border::BORDER_DASHDOTDOT],
['1dot', Border::BORDER_DOTTED],
['1double', Border::BORDER_DOUBLE],
['2continuous', Border::BORDER_MEDIUM],
['2dash', Border::BORDER_MEDIUMDASHED],
['2dashdot', Border::BORDER_MEDIUMDASHDOT],
['2dashdotdot', Border::BORDER_MEDIUMDASHDOTDOT],
['2dot', Border::BORDER_DOTTED],
['2double', Border::BORDER_DOUBLE],
['3continuous', Border::BORDER_THICK],
['3dash', Border::BORDER_MEDIUMDASHED],
['3dashdot', Border::BORDER_MEDIUMDASHDOT],
['3dashdotdot', Border::BORDER_MEDIUMDASHDOTDOT],
['3dot', Border::BORDER_DOTTED],
['3double', Border::BORDER_DOUBLE],
];
}
public static function providerFillType(): array
{
return [
['solid', Fill::FILL_SOLID],
['gray75', Fill::FILL_PATTERN_DARKGRAY],
['gray50', Fill::FILL_PATTERN_MEDIUMGRAY],
['gray25', Fill::FILL_PATTERN_LIGHTGRAY],
['gray125', Fill::FILL_PATTERN_GRAY125],
['gray0625', Fill::FILL_PATTERN_GRAY0625],
['horzstripe', Fill::FILL_PATTERN_DARKHORIZONTAL],
['vertstripe', Fill::FILL_PATTERN_DARKVERTICAL],
['reversediagstripe', Fill::FILL_PATTERN_DARKUP],
['diagstripe', Fill::FILL_PATTERN_DARKDOWN],
['diagcross', Fill::FILL_PATTERN_DARKGRID],
['thickdiagcross', Fill::FILL_PATTERN_DARKTRELLIS],
['thinhorzstripe', Fill::FILL_PATTERN_LIGHTHORIZONTAL],
['thinvertstripe', Fill::FILL_PATTERN_LIGHTVERTICAL],
['thinreversediagstripe', Fill::FILL_PATTERN_LIGHTUP],
['thindiagstripe', Fill::FILL_PATTERN_LIGHTDOWN],
['thinhorzcross', Fill::FILL_PATTERN_LIGHTGRID],
['thindiagcross', Fill::FILL_PATTERN_LIGHTTRELLIS],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Xml/XmlRichTextTest.php | tests/PhpSpreadsheetTests/Reader/Xml/XmlRichTextTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xml;
use PhpOffice\PhpSpreadsheet\Reader\Xml;
use PhpOffice\PhpSpreadsheet\RichText\RichText;
use PhpOffice\PhpSpreadsheet\RichText\Run;
use PHPUnit\Framework\TestCase;
class XmlRichTextTest extends TestCase
{
public function testBreakTag(): void
{
$xmldata = <<< 'EOT'
<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<Worksheet ss:Name="Test">
<ss:Table>
<ss:Row>
<ss:Cell>
<ss:Data ss:Type="String" xmlns="http://www.w3.org/TR/REC-html40"><I>italic</I><B>bold</B><BR />second line</ss:Data>
</ss:Cell>
</ss:Row>
</ss:Table>
</Worksheet>
</Workbook>
EOT;
$reader = new Xml();
$spreadsheet = $reader->loadSpreadsheetFromString($xmldata);
self::assertEquals(1, $spreadsheet->getSheetCount());
$sheet = $spreadsheet->getActiveSheet();
self::assertEquals('Test', $sheet->getTitle());
$richText = $sheet->getCell('A1')->getValue();
self::assertInstanceOf(RichText::class, $richText);
$elements = $richText->getRichTextElements();
self::assertCount(3, $elements);
$run = $elements[0];
self::assertInstanceOf(Run::class, $run);
self::assertSame('italic', $run->getText());
self::assertNotNull($run->getFont());
self::assertTrue($run->getFont()->getItalic());
self::assertFalse($run->getFont()->getBold());
$run = $elements[1];
self::assertInstanceOf(Run::class, $run);
self::assertSame('bold', $run->getText());
self::assertNotNull($run->getFont());
self::assertFalse($run->getFont()->getItalic());
self::assertTrue($run->getFont()->getBold());
$run = $elements[2];
self::assertInstanceOf(Run::class, $run);
self::assertSame("\nsecond line", $run->getText());
$spreadsheet->disconnectWorksheets();
}
public function testNewlineAndFontTag(): void
{
$xmldata = <<< 'EOT'
<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
<LastAuthor>Owen Leibman</LastAuthor>
<Created>2024-04-28T06:03:14Z</Created>
<Version>16.00</Version>
</DocumentProperties>
<OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">
<AllowPNG/>
</OfficeDocumentSettings>
<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
<WindowHeight>6510</WindowHeight>
<WindowWidth>19200</WindowWidth>
<WindowTopX>32767</WindowTopX>
<WindowTopY>32767</WindowTopY>
<ProtectStructure>False</ProtectStructure>
<ProtectWindows>False</ProtectWindows>
</ExcelWorkbook>
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Bottom"/>
<Borders/>
<Font ss:FontName="Aptos Narrow" x:Family="Swiss" ss:Size="11"
ss:Color="#000000"/>
<Interior/>
<NumberFormat/>
<Protection/>
</Style>
<Style ss:ID="s63">
<Alignment ss:Vertical="Bottom" ss:WrapText="1"/>
<Borders/>
<Font ss:FontName="Aptos Narrow" x:Family="Swiss" ss:Size="11" ss:Italic="1"/>
<Interior/>
<NumberFormat/>
<Protection/>
</Style>
</Styles>
<Worksheet ss:Name="Test">
<Table ss:ExpandedColumnCount="1" ss:ExpandedRowCount="1" x:FullColumns="1"
x:FullRows="1" ss:DefaultRowHeight="14.5">
<Row ss:AutoFitHeight="0" ss:Height="47.5">
<Cell ss:StyleID="s63"><ss:Data ss:Type="String"
xmlns="http://www.w3.org/TR/REC-html40"><I>italic</I><B>bold </B><Font
html:Color="#FF0000">second</Font><Font> line</Font></ss:Data></Cell>
</Row>
</Table>
<WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
<Unsynced/>
<Selected/>
<ProtectObjects>False</ProtectObjects>
<ProtectScenarios>False</ProtectScenarios>
</WorksheetOptions>
</Worksheet>
</Workbook>
EOT;
$reader = new Xml();
$spreadsheet = $reader->loadSpreadsheetFromString($xmldata);
self::assertEquals(1, $spreadsheet->getSheetCount());
$sheet = $spreadsheet->getActiveSheet();
self::assertEquals('Test', $sheet->getTitle());
$richText = $sheet->getCell('A1')->getValue();
self::assertInstanceOf(RichText::class, $richText);
$elements = $richText->getRichTextElements();
self::assertCount(4, $elements);
$run = $elements[0];
self::assertInstanceOf(Run::class, $run);
self::assertSame('italic', $run->getText());
self::assertNotNull($run->getFont());
self::assertTrue($run->getFont()->getItalic());
self::assertFalse($run->getFont()->getBold());
$run = $elements[1];
self::assertInstanceOf(Run::class, $run);
self::assertSame("bold\n", $run->getText());
self::assertNotNull($run->getFont());
self::assertFalse($run->getFont()->getItalic());
self::assertTrue($run->getFont()->getBold());
$run = $elements[2];
self::assertInstanceOf(Run::class, $run);
self::assertSame('second', $run->getText());
self::assertSame('FF0000', $run->getFont()?->getColor()->getRgb());
$run = $elements[3];
self::assertInstanceOf(Run::class, $run);
self::assertSame(' line', $run->getText());
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Xml/SplitsTest.php | tests/PhpSpreadsheetTests/Reader/Xml/SplitsTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xml;
use PhpOffice\PhpSpreadsheet\Reader\Xml;
use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional;
class SplitsTest extends AbstractFunctional
{
private static string $testbook = 'tests/data/Reader/Xml/splits.xml';
public function testSplits(): void
{
$reader = new Xml();
$spreadsheet = $reader->load(self::$testbook);
$sheet = $spreadsheet->getSheetByNameOrThrow('Freeze');
self::assertSame('frozen', $sheet->getPaneState());
self::assertSame('E7', $sheet->getFreezePane());
self::assertSame('L7', $sheet->getPaneTopLeftCell());
self::assertSame('L7', $sheet->getTopLeftCell());
//self::assertSame('L7', $sheet->getSelectedCells());
$sheet = $spreadsheet->getSheetByNameOrThrow('SplitVertical');
self::assertNull($sheet->getFreezePane());
self::assertSame('G1', $sheet->getTopLeftCell());
self::assertSame('E1', $sheet->getPaneTopLeftCell());
self::assertNotEquals(0, $sheet->getXSplit());
self::assertEquals(0, $sheet->getYSplit());
//self::assertSame('E1', $sheet->getSelectedCells());
//self::assertNotNull($sheet->getPane('topRight'));
$sheet = $spreadsheet->getSheetByNameOrThrow('SplitHorizontal');
self::assertNull($sheet->getFreezePane());
self::assertSame('A3', $sheet->getTopLeftCell());
self::assertSame('A6', $sheet->getPaneTopLeftCell());
self::assertEquals(0, $sheet->getXSplit());
self::assertNotEquals(0, $sheet->getYSplit());
//self::assertSame('A7', $sheet->getSelectedCells());
//self::assertNotNull($sheet->getPane('bottomLeft'));
$sheet = $spreadsheet->getSheetByNameOrThrow('SplitBoth');
self::assertNull($sheet->getFreezePane());
self::assertSame('H3', $sheet->getTopLeftCell());
self::assertSame('E19', $sheet->getPaneTopLeftCell());
self::assertNotEquals(0, $sheet->getXSplit());
self::assertNotEquals(0, $sheet->getYSplit());
//self::assertSame('E20', $sheet->getSelectedCells());
//self::assertNotNull($sheet->getPane('bottomLeft'));
//self::assertNotNull($sheet->getPane('bottomRight'));
//self::assertNotNull($sheet->getPane('topRight'));
$sheet = $spreadsheet->getSheetByNameOrThrow('NoFreezeNorSplit');
self::assertNull($sheet->getFreezePane());
self::assertSame('D3', $sheet->getTopLeftCell());
self::assertSame('', $sheet->getPaneTopLeftCell());
self::assertSame('D5', $sheet->getSelectedCells());
self::assertNull($sheet->getPane('bottomLeft'));
self::assertNull($sheet->getPane('bottomRight'));
self::assertNull($sheet->getPane('topRight'));
$sheet = $spreadsheet->getSheetByNameOrThrow('FrozenSplit');
self::assertSame('B4', $sheet->getFreezePane());
self::assertSame('frozenSplit', $sheet->getPaneState());
self::assertSame('B4', $sheet->getPaneTopLeftCell());
self::assertSame('B4', $sheet->getTopLeftCell());
//self::assertSame('B4', $sheet->getSelectedCells());
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Xml/HtmlEntitiesLoadTest.php | tests/PhpSpreadsheetTests/Reader/Xml/HtmlEntitiesLoadTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xml;
use PhpOffice\PhpSpreadsheet\Reader\Xml as XmlReader;
use PHPUnit\Framework\TestCase;
class HtmlEntitiesLoadTest extends TestCase
{
public static function testIssue2157(): void
{
$infile = 'tests/data/Reader/Xml/issue.2157.small.xml';
$contents = (string) file_get_contents($infile);
self::assertSame("\t", substr($contents, 0, 1));
self::assertStringContainsString('Τ', $contents);
self::assertStringContainsString('</br>', $contents);
self::assertStringNotContainsString('Τ', $contents); // that's a Tau, not T
self::assertStringNotContainsString('</br>', $contents);
$reader = new XmlReader();
$spreadsheet = $reader->load($infile);
$sheet = $spreadsheet->getActiveSheet();
self::assertSame('Τέλεια όραση χωρίς γυαλιά', $sheet->getCell('E2')->getValue());
$g2 = $sheet->getCell('G2')->getValue();
self::assertStringContainsString('</br>', $g2);
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Xml/XmlOddTest.php | tests/PhpSpreadsheetTests/Reader/Xml/XmlOddTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xml;
use PhpOffice\PhpSpreadsheet\Reader\Xml;
use PhpOffice\PhpSpreadsheet\Shared\File;
use PHPUnit\Framework\TestCase;
class XmlOddTest extends TestCase
{
private string $filename = '';
protected function teardown(): void
{
if ($this->filename) {
unlink($this->filename);
$this->filename = '';
}
}
public function testWriteThenRead(): void
{
$xmldata = <<< 'EOT'
<?xml version="1.0" encoding="UTF-8"?><?mso-application progid="Excel.Sheet"?>
<Workbook xmlns:c="urn:schemas-microsoft-com:office:component:spreadsheet"
xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
>
<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
<Title>Xml2003 Short Workbook</Title>
</DocumentProperties>
<CustomDocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
<my_x05d0_Int dt:dt="integer">2</my_x05d0_Int>
</CustomDocumentProperties>
<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
<WindowHeight>9000</WindowHeight>
<WindowWidth>13860</WindowWidth>
<WindowTopX>240</WindowTopX>
<WindowTopY>75</WindowTopY>
<ProtectStructure>False</ProtectStructure>
<ProtectWindows>False</ProtectWindows>
</ExcelWorkbook>
<ss:Worksheet ss:Name="Sample Data">
<Table>
<Column ss:Width="96.4913"/>
<Row ss:Index="8" ss:AutoFitHeight="0" ss:Height="14.9953">
<Cell>
<ss:Data ss:Type="String">Test String 1</ss:Data>
</Cell>
</Row>
</Table>
</ss:Worksheet>
</Workbook>
EOT;
$this->filename = File::temporaryFilename();
file_put_contents($this->filename, $xmldata);
$reader = new Xml();
$spreadsheet = $reader->load($this->filename);
self::assertEquals(1, $spreadsheet->getSheetCount());
$sheet = $spreadsheet->getActiveSheet();
self::assertEquals('Sample Data', $sheet->getTitle());
self::assertEquals('Test String 1', $sheet->getCell('A8')->getValue());
$props = $spreadsheet->getProperties();
self::assertEquals('Xml2003 Short Workbook', $props->getTitle());
self::assertEquals('2', $props->getCustomPropertyValue('myאInt'));
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Xml/XmlFreezePanesTest.php | tests/PhpSpreadsheetTests/Reader/Xml/XmlFreezePanesTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xml;
use PhpOffice\PhpSpreadsheet\Reader\Xml;
use PHPUnit\Framework\TestCase;
class XmlFreezePanesTest extends TestCase
{
public function testColSpan(): void
{
$xmldata = <<< 'EOT'
<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<Worksheet ss:Name="Tabelle1">
<Table>
</Table>
<WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
<FreezePanes/>
<SplitHorizontal>2</SplitHorizontal>
<TopRowBottomPane>10</TopRowBottomPane>
<SplitVertical>6</SplitVertical>
<LeftColumnRightPane>20</LeftColumnRightPane>
</WorksheetOptions>
</Worksheet>
</Workbook>
EOT;
$reader = new Xml();
$spreadsheet = $reader->loadSpreadsheetFromString($xmldata);
self::assertEquals(1, $spreadsheet->getSheetCount());
$sheet = $spreadsheet->getActiveSheet();
self::assertSame('Tabelle1', $sheet->getTitle());
self::assertSame('G3', $sheet->getFreezePane());
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Xml/ReadOrderTest.php | tests/PhpSpreadsheetTests/Reader/Xml/ReadOrderTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xml;
use PhpOffice\PhpSpreadsheet\Reader\Xml as XmlReader;
use PhpOffice\PhpSpreadsheet\Style\Alignment;
use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional;
class ReadOrderTest extends AbstractFunctional
{
public function testReadOrder(): void
{
// Issue 850 - Xls Reader/Writer didn't support Alignment ReadOrder
$infile = 'tests/data/Reader/Xml/issue.850.xml';
$reader = new XmlReader();
$robj = $reader->load($infile);
$sheet0 = $robj->setActiveSheetIndex(0);
self::assertSame(
Alignment::READORDER_RTL,
$sheet0->getStyle('A1')->getAlignment()->getReadOrder()
);
self::assertSame(
Alignment::READORDER_LTR,
$sheet0->getStyle('A2')->getAlignment()->getReadOrder()
);
self::assertSame(
Alignment::READORDER_CONTEXT,
$sheet0->getStyle('A3')->getAlignment()->getReadOrder()
);
self::assertSame(
2,
$sheet0->getStyle('A5')->getAlignment()->getIndent()
);
$robj->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Xml/XmlFontBoldItalicTest.php | tests/PhpSpreadsheetTests/Reader/Xml/XmlFontBoldItalicTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xml;
use PhpOffice\PhpSpreadsheet\Reader\Xml;
use PHPUnit\Framework\TestCase;
class XmlFontBoldItalicTest extends TestCase
{
public function testFontBoldItalic(): void
{
$xmldata = <<< 'EOT'
<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
<Author>Owen Leibman</Author>
<LastAuthor>Owen Leibman</LastAuthor>
<Created>2023-05-15T17:04:33Z</Created>
<Version>16.00</Version>
</DocumentProperties>
<CustomDocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
<MSIP_Label_b002e552-5bac-4e77-a8f2-1e8fdcadcedf_Enabled dt:dt="string">true</MSIP_Label_b002e552-5bac-4e77-a8f2-1e8fdcadcedf_Enabled>
<MSIP_Label_b002e552-5bac-4e77-a8f2-1e8fdcadcedf_SetDate dt:dt="string">2023-05-15T17:06:02Z</MSIP_Label_b002e552-5bac-4e77-a8f2-1e8fdcadcedf_SetDate>
<MSIP_Label_b002e552-5bac-4e77-a8f2-1e8fdcadcedf_Method dt:dt="string">Standard</MSIP_Label_b002e552-5bac-4e77-a8f2-1e8fdcadcedf_Method>
<MSIP_Label_b002e552-5bac-4e77-a8f2-1e8fdcadcedf_Name dt:dt="string">defa4170-0d19-0005-0004-bc88714345d2</MSIP_Label_b002e552-5bac-4e77-a8f2-1e8fdcadcedf_Name>
<MSIP_Label_b002e552-5bac-4e77-a8f2-1e8fdcadcedf_SiteId dt:dt="string">f9465cb1-7889-4d9a-b552-fdd0addf0eb1</MSIP_Label_b002e552-5bac-4e77-a8f2-1e8fdcadcedf_SiteId>
<MSIP_Label_b002e552-5bac-4e77-a8f2-1e8fdcadcedf_ActionId dt:dt="string">55f09022-fb59-44b6-a7c5-9d50704243d3</MSIP_Label_b002e552-5bac-4e77-a8f2-1e8fdcadcedf_ActionId>
<MSIP_Label_b002e552-5bac-4e77-a8f2-1e8fdcadcedf_ContentBits dt:dt="string">0</MSIP_Label_b002e552-5bac-4e77-a8f2-1e8fdcadcedf_ContentBits>
</CustomDocumentProperties>
<OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">
<AllowPNG/>
</OfficeDocumentSettings>
<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
<WindowHeight>6820</WindowHeight>
<WindowWidth>19200</WindowWidth>
<WindowTopX>32767</WindowTopX>
<WindowTopY>32767</WindowTopY>
<ProtectStructure>False</ProtectStructure>
<ProtectWindows>False</ProtectWindows>
</ExcelWorkbook>
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Bottom"/>
<Borders/>
<Font ss:FontName="Calibri" x:Family="Swiss" ss:Size="11" ss:Color="#000000"/>
<Interior/>
<NumberFormat/>
<Protection/>
</Style>
<Style ss:ID="s62">
<Font ss:FontName="Calibri" x:Family="Swiss" ss:Size="11" ss:Color="#000000"
ss:Bold="1"/>
</Style>
<Style ss:ID="s62nb">
<Font ss:FontName="Calibri" x:Family="Swiss" ss:Size="11" ss:Color="#000000"
ss:Bold="0"/>
</Style>
<Style ss:ID="s64">
<Font ss:FontName="Calibri" x:Family="Swiss" ss:Size="11" ss:Color="#000000"
ss:Bold="1" ss:Italic="1"/>
</Style>
<Style ss:ID="s65">
<Font ss:FontName="Calibri" x:Family="Swiss" ss:Size="11" ss:Color="#000000"
ss:Italic="1"/>
</Style>
<Style ss:ID="s65ni">
<Font ss:FontName="Calibri" x:Family="Swiss" ss:Size="11" ss:Color="#000000"
ss:Italic="0"/>
</Style>
</Styles>
<Worksheet ss:Name="Sheet1">
<Table ss:ExpandedColumnCount="2" ss:ExpandedRowCount="4" x:FullColumns="1"
x:FullRows="1" ss:DefaultRowHeight="14.5">
<Row ss:AutoFitHeight="0">
<Cell><Data ss:Type="String">normal</Data></Cell>
<Cell><Data ss:Type="String">normal</Data></Cell>
</Row>
<Row ss:AutoFitHeight="0">
<Cell ss:StyleID="s62"><Data ss:Type="String">bold</Data></Cell>
<Cell ss:StyleID="s62nb"><Data ss:Type="String">not bold</Data></Cell>
</Row>
<Row ss:AutoFitHeight="0">
<Cell ss:StyleID="s65"><Data ss:Type="String">italic</Data></Cell>
<Cell ss:StyleID="s65ni"><Data ss:Type="String">not italic</Data></Cell>
</Row>
<Row ss:AutoFitHeight="0">
<Cell ss:StyleID="s64"><Data ss:Type="String">bold italic</Data></Cell>
<Cell ss:StyleID="s64"><Data ss:Type="String">bold italic</Data></Cell>
</Row>
</Table>
<WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
<PageSetup>
<Header x:Margin="0.3"/>
<Footer x:Margin="0.3"/>
<PageMargins x:Bottom="0.75" x:Left="0.7" x:Right="0.7" x:Top="0.75"/>
</PageSetup>
<Unsynced/>
<Print>
<ValidPrinterInfo/>
<HorizontalResolution>600</HorizontalResolution>
<VerticalResolution>600</VerticalResolution>
</Print>
<Selected/>
<Panes>
<Pane>
<Number>3</Number>
<ActiveRow>2</ActiveRow>
<ActiveCol>1</ActiveCol>
</Pane>
</Panes>
<ProtectObjects>False</ProtectObjects>
<ProtectScenarios>False</ProtectScenarios>
</WorksheetOptions>
</Worksheet>
</Workbook>
EOT;
$reader = new Xml();
$spreadsheet = $reader->loadSpreadsheetFromString($xmldata);
self::assertEquals(1, $spreadsheet->getSheetCount());
$sheet = $spreadsheet->getActiveSheet();
self::assertEquals('Sheet1', $sheet->getTitle());
self::assertFalse($sheet->getStyle('A1')->getFont()->getBold());
self::assertFalse($sheet->getStyle('A1')->getFont()->getItalic());
self::assertTrue($sheet->getStyle('A2')->getFont()->getBold());
self::assertFalse($sheet->getStyle('A2')->getFont()->getItalic());
self::assertFalse($sheet->getStyle('A3')->getFont()->getBold());
self::assertTrue($sheet->getStyle('A3')->getFont()->getItalic());
self::assertTrue($sheet->getStyle('A4')->getFont()->getBold());
self::assertTrue($sheet->getStyle('A4')->getFont()->getItalic());
self::assertFalse($sheet->getStyle('B1')->getFont()->getBold());
self::assertFalse($sheet->getStyle('B1')->getFont()->getItalic());
self::assertFalse($sheet->getStyle('B2')->getFont()->getBold(), 'xml specifies bold=0');
self::assertFalse($sheet->getStyle('B2')->getFont()->getItalic());
self::assertFalse($sheet->getStyle('B3')->getFont()->getBold());
self::assertFalse($sheet->getStyle('B3')->getFont()->getItalic(), 'xml specifies italic=0');
self::assertTrue($sheet->getStyle('B4')->getFont()->getBold());
self::assertTrue($sheet->getStyle('B4')->getFont()->getItalic());
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Xml/XmlIssue4000Test.php | tests/PhpSpreadsheetTests/Reader/Xml/XmlIssue4000Test.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xml;
use PhpOffice\PhpSpreadsheet\Reader\Xml;
use PhpOffice\PhpSpreadsheet\Style\Border;
use PHPUnit\Framework\TestCase;
class XmlIssue4000Test extends TestCase
{
public function testFontBoldItalic(): void
{
// Styles tag and children have ss: prefixes
$xmldata = <<< 'EOT'
<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
<Version>16.00</Version>
</DocumentProperties>
<OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">
<AllowPNG/>
</OfficeDocumentSettings>
<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
<WindowHeight>6510</WindowHeight>
<WindowWidth>19200</WindowWidth>
<WindowTopX>32767</WindowTopX>
<WindowTopY>32767</WindowTopY>
<ProtectStructure>False</ProtectStructure>
<ProtectWindows>False</ProtectWindows>
</ExcelWorkbook>
<ss:Styles>
<ss:Style ss:ID="Default" ss:Name="Normal">
<ss:Alignment ss:Vertical="Bottom"/>
<ss:Borders/>
<ss:Font ss:FontName="Aptos Narrow" x:Family="Swiss" ss:Size="11"
ss:Color="#000000"/>
<ss:Interior/>
<ss:NumberFormat/>
<ss:Protection/>
</ss:Style>
<ss:Style ss:ID="s63">
<ss:Alignment ss:Vertical="Bottom"/>
<ss:Borders>
<ss:Border ss:Position="Bottom" ss:LineStyle="Double" ss:Weight="3"/>
<ss:Border ss:Position="Left" ss:LineStyle="Continuous"/>
<ss:Border ss:Position="Right" ss:LineStyle="DashDot" ss:Weight="2"/>
<ss:Border ss:Position="Top" ss:LineStyle="Dash" ss:Weight="1"/>
</ss:Borders>
<ss:Font ss:FontName="Aptos Narrow" x:Family="Swiss" ss:Size="11"
ss:Color="#000000" ss:Bold="1"/>
<ss:Interior/>
<ss:NumberFormat/>
<ss:Protection/>
</ss:Style>
</ss:Styles>
<Worksheet ss:Name="Test">
<Table ss:ExpandedColumnCount="2" ss:ExpandedRowCount="2" x:FullColumns="1"
x:FullRows="1" ss:DefaultRowHeight="14.5">
<Row ss:Index="2" ss:Height="15">
<Cell ss:Index="2" ss:StyleID="s63"><Data ss:Type="String">TEST</Data></Cell>
</Row>
</Table>
<WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
<Selected/>
<ProtectObjects>False</ProtectObjects>
<ProtectScenarios>False</ProtectScenarios>
</WorksheetOptions>
</Worksheet>
</Workbook>
EOT;
$reader = new Xml();
$spreadsheet = $reader->loadSpreadsheetFromString($xmldata);
self::assertEquals(1, $spreadsheet->getSheetCount());
$sheet = $spreadsheet->getActiveSheet();
self::assertEquals('Test', $sheet->getTitle());
self::assertSame(Border::BORDER_DOUBLE, $sheet->getStyle('B2')->getBorders()->getBottom()->getBorderStyle());
self::assertSame(Border::BORDER_MEDIUMDASHDOT, $sheet->getStyle('B2')->getBorders()->getRight()->getBorderStyle());
self::assertSame(Border::BORDER_DASHED, $sheet->getStyle('B2')->getBorders()->getTop()->getBorderStyle());
self::assertSame(Border::BORDER_HAIR, $sheet->getStyle('B2')->getBorders()->getLeft()->getBorderStyle());
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Xml/XmlColSpanTest.php | tests/PhpSpreadsheetTests/Reader/Xml/XmlColSpanTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xml;
use PhpOffice\PhpSpreadsheet\Reader\Xml;
use PHPUnit\Framework\TestCase;
class XmlColSpanTest extends TestCase
{
public function testColSpan(): void
{
$xmldata = <<< 'EOT'
<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
<Version>16.00</Version>
</DocumentProperties>
<OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">
<AllowPNG/>
</OfficeDocumentSettings>
<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
<WindowHeight>6820</WindowHeight>
<WindowWidth>19200</WindowWidth>
<WindowTopX>32767</WindowTopX>
<WindowTopY>32767</WindowTopY>
<ProtectStructure>False</ProtectStructure>
<ProtectWindows>False</ProtectWindows>
</ExcelWorkbook>
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Bottom"/>
<Borders/>
<Font ss:FontName="Calibri" x:Family="Swiss" ss:Size="11" ss:Color="#000000"/>
<Interior/>
<NumberFormat/>
<Protection/>
</Style>
</Styles>
<Worksheet ss:Name="Tabelle1">
<Table ss:ExpandedColumnCount="6" ss:ExpandedRowCount="1" x:FullColumns="1"
x:FullRows="1" ss:DefaultColumnWidth="60" ss:DefaultRowHeight="14.5">
<Column ss:AutoFitWidth="0" ss:Width="76.5"/>
<Column ss:AutoFitWidth="0" ss:Width="25.5" ss:Span="3"/>
<Row ss:AutoFitHeight="0">
<Cell><Data ss:Type="String">wide</Data></Cell>
<Cell><Data ss:Type="String">thin</Data></Cell>
<Cell><Data ss:Type="String">thin</Data></Cell>
<Cell><Data ss:Type="String">thin</Data></Cell>
<Cell><Data ss:Type="String">thin</Data></Cell>
<Cell><Data ss:Type="String">normal</Data></Cell>
</Row>
</Table>
<WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
<Unsynced/>
<Selected/>
<Panes>
<Pane>
<Number>3</Number>
<ActiveRow>1</ActiveRow>
</Pane>
</Panes>
<ProtectObjects>False</ProtectObjects>
<ProtectScenarios>False</ProtectScenarios>
</WorksheetOptions>
</Worksheet>
</Workbook>
EOT;
$reader = new Xml();
$spreadsheet = $reader->loadSpreadsheetFromString($xmldata);
self::assertEquals(1, $spreadsheet->getSheetCount());
$sheet = $spreadsheet->getActiveSheet();
self::assertSame('Tabelle1', $sheet->getTitle());
self::assertSame('A2', $sheet->getSelectedCells());
$widthMultiplier = 5.4;
$expectedWidthBtoE = 25.5 / $widthMultiplier;
self::assertEqualsWithDelta($expectedWidthBtoE, $sheet->getColumnDimension('B')->getWidth(), 1E-6, '1st col in span');
self::assertEqualsWithDelta($expectedWidthBtoE, $sheet->getColumnDimension('C')->getWidth(), 1E-6, '2nd col in span');
self::assertEqualsWithDelta($expectedWidthBtoE, $sheet->getColumnDimension('D')->getWidth(), 1E-6, '3rd col in span');
self::assertEqualsWithDelta($expectedWidthBtoE, $sheet->getColumnDimension('E')->getWidth(), 1E-6, '4th col in span');
$expectedWidthA = 76.5 / $widthMultiplier;
self::assertEqualsWithDelta($expectedWidthA, $sheet->getColumnDimension('A')->getWidth(), 1E-6, 'width without span');
self::assertEqualsWithDelta(-1.0, $sheet->getColumnDimension('F')->getWidth(), 1E-6, 'default width');
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Xml/XmlLoadTest.php | tests/PhpSpreadsheetTests/Reader/Xml/XmlLoadTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xml;
use DateTimeZone;
use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException;
use PhpOffice\PhpSpreadsheet\Reader\Xml;
use PhpOffice\PhpSpreadsheet\Settings;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase;
class XmlLoadTest extends TestCase
{
private ?Spreadsheet $spreadsheet = null;
private string $locale;
protected function setUp(): void
{
$this->locale = Settings::getLocale();
}
protected function tearDown(): void
{
if ($this->spreadsheet !== null) {
$this->spreadsheet->disconnectWorksheets();
$this->spreadsheet = null;
}
Settings::setLocale($this->locale);
}
public function testLoadEnglish(): void
{
$this->xtestLoad();
}
public function testLoadFrench(): void
{
Settings::setLocale('fr');
$this->xtestLoad();
}
public function xtestLoad(): void
{
$filename = __DIR__
. '/../../../..'
. '/samples/templates/excel2003.xml';
$reader = new Xml();
$this->spreadsheet = $spreadsheet = $reader->load($filename);
self::assertEquals(2, $spreadsheet->getSheetCount());
$sheet = $spreadsheet->getSheet(1);
self::assertEquals('Report Data', $sheet->getTitle());
self::assertEquals('BCD', $sheet->getCell('A4')->getValue());
$props = $spreadsheet->getProperties();
self::assertEquals('Mark Baker', $props->getCreator());
$creationDate = $props->getCreated();
$result = Date::formattedDateTimeFromTimestamp("$creationDate", 'Y-m-d\TH:i:s\Z', new DateTimeZone('UTC'));
self::assertEquals('2010-09-02T20:48:39Z', $result);
$creationDate = $props->getModified();
$result = Date::formattedDateTimeFromTimestamp("$creationDate", 'Y-m-d\TH:i:s\Z', new DateTimeZone('UTC'));
self::assertEquals('2010-09-03T21:48:39Z', $result);
self::assertEquals('AbCd1234', $props->getCustomPropertyValue('my_API_Token'));
self::assertEquals('2', $props->getCustomPropertyValue('myאInt'));
/** @var string */
$creationDate = $props->getCustomPropertyValue('my_API_Token_Expiry');
$result = Date::formattedDateTimeFromTimestamp("$creationDate", 'Y-m-d\TH:i:s\Z', new DateTimeZone('UTC'));
self::assertEquals('2019-01-31T07:00:00Z', $result);
$sheet = $spreadsheet->getSheet(0);
self::assertEquals('Sample Data', $sheet->getTitle());
self::assertEquals('Test String 1', $sheet->getCell('A1')->getValue());
self::assertEquals('Test with (") in string', $sheet->getCell('A4')->getValue());
self::assertEquals(22269, $sheet->getCell('A10')->getValue());
self::assertEquals('dd/mm/yyyy', $sheet->getCell('A10')->getStyle()->getNumberFormat()->getFormatCode());
self::assertEquals('19/12/1960', $sheet->getCell('A10')->getFormattedValue());
self::assertEquals(1.5, $sheet->getCell('A11')->getValue());
self::assertEquals('# ?0/??0', $sheet->getCell('A11')->getStyle()->getNumberFormat()->getFormatCode());
// Same pattern, same value, different display in Gnumeric vs Excel
//self::assertEquals('1 1/2', $sheet->getCell('A11')->getFormattedValue());
self::assertEquals('hh":"mm":"ss', $sheet->getCell('A13')->getStyle()->getNumberFormat()->getFormatCode());
self::assertEquals('02:30:00', $sheet->getCell('A13')->getFormattedValue());
self::assertEquals('d/m/yy hh":"mm', $sheet->getCell('A15')->getStyle()->getNumberFormat()->getFormatCode());
self::assertEquals('19/12/60 01:30', $sheet->getCell('A15')->getFormattedValue());
self::assertEquals('=B1+C1', $sheet->getCell('H1')->getValue());
self::assertEquals('=E2&F2', $sheet->getCell('J2')->getValue());
self::assertEquals('=SUM(C1:C4)', $sheet->getCell('I5')->getValue());
// property not yet supported
//self::assertFalse($sheet->getRowDimension(30)->getVisible());
$hyperlink = $sheet->getCell('A21');
self::assertEquals('PhpSpreadsheet', $hyperlink->getValue());
self::assertEquals('https://github.com/PHPOffice/PhpSpreadsheet', $hyperlink->getHyperlink()->getUrl());
}
public function testLoadFilter(): void
{
$filename = __DIR__
. '/../../../..'
. '/samples/templates/excel2003.xml';
$reader = new Xml();
$filter = new XmlFilter();
$reader->setReadFilter($filter);
$this->spreadsheet = $spreadsheet = $reader->load($filename);
self::assertEquals(2, $spreadsheet->getSheetCount());
$sheet = $spreadsheet->getSheet(1);
self::assertEquals('Report Data', $sheet->getTitle());
self::assertEquals('', $sheet->getCell('A4')->getValue());
$props = $spreadsheet->getProperties();
self::assertEquals('Mark Baker', $props->getCreator());
}
public function testLoadSelectedSheets(): void
{
$filename = __DIR__
. '/../../../..'
. '/samples/templates/excel2003.xml';
$reader = new Xml();
$reader->setLoadSheetsOnly(['Unknown Sheet', 'Report Data']);
$this->spreadsheet = $spreadsheet = $reader->load($filename);
self::assertEquals(1, $spreadsheet->getSheetCount());
$sheet = $spreadsheet->getSheet(0);
self::assertEquals('Report Data', $sheet->getTitle());
self::assertEquals('Third Heading', $sheet->getCell('C2')->getValue());
}
public function testLoadNoSelectedSheets(): void
{
$this->expectException(PhpSpreadsheetException::class);
$this->expectExceptionMessage('You tried to set a sheet active by the out of bounds index');
$filename = __DIR__
. '/../../../..'
. '/samples/templates/excel2003.xml';
$reader = new Xml();
$reader->setLoadSheetsOnly(['Unknown Sheet', 'xReport Data']);
$this->spreadsheet = $reader->load($filename);
}
public function testLoadUnusableSample(): void
{
// Sample spreadsheet is not readable by Excel.
// But PhpSpreadsheet can load it.
$filename = __DIR__
. '/../../../..'
. '/samples/templates/excel2003.short.bad.xml';
$reader = new Xml();
$this->spreadsheet = $spreadsheet = $reader->load($filename);
self::assertEquals(1, $spreadsheet->getSheetCount());
$sheet = $spreadsheet->getSheet(0);
self::assertEquals('Sample Data', $sheet->getTitle());
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Xml/XmlProtectionTest.php | tests/PhpSpreadsheetTests/Reader/Xml/XmlProtectionTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xml;
use PhpOffice\PhpSpreadsheet\Reader\Xml;
use PHPUnit\Framework\TestCase;
class XmlProtectionTest extends TestCase
{
public function testProtection(): void
{
$xmldata = <<< 'EOT'
<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40">
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Protection x:HideFormula="1" ss:Protected="1"/>
</Style>
<Style ss:ID="visible">
<Protection x:HideFormula="0" ss:Protected="1"/>
</Style>
<Style ss:ID="writable">
<Protection x:HideFormula="1" ss:Protected="0"/>
</Style>
<Style ss:ID="neither">
</Style>
</Styles>
<Worksheet ss:Name="sheet 1" ss:Protected="1">
<ss:Table>
<ss:Row>
<ss:Cell ss:Formula="=1">
<ss:Data ss:Type="Number"/>
</ss:Cell>
<ss:Cell ss:StyleID="visible" ss:Formula="=2">
<ss:Data ss:Type="Number"/>
</ss:Cell>
<ss:Cell ss:StyleID="writable" ss:Formula="=3">
<ss:Data ss:Type="Number"/>
</ss:Cell>
</ss:Row>
</ss:Table>
</Worksheet>
</Workbook>
EOT;
$reader = new Xml();
$spreadsheet = $reader->loadSpreadsheetFromString($xmldata);
self::assertEquals(1, $spreadsheet->getSheetCount());
$sheet = $spreadsheet->getActiveSheet();
self::assertEquals('sheet 1', $sheet->getTitle());
self::assertTrue($sheet->getProtection()->isProtectionEnabled());
self::assertSame('protected', $sheet->getCell('A1')->getStyle()->getProtection()->getLocked());
self::assertSame('protected', $sheet->getCell('A1')->getStyle()->getProtection()->getHidden());
self::assertSame('protected', $sheet->getCell('B1')->getStyle()->getProtection()->getLocked());
self::assertSame('unprotected', $sheet->getCell('B1')->getStyle()->getProtection()->getHidden());
self::assertSame('unprotected', $sheet->getCell('C1')->getStyle()->getProtection()->getLocked());
self::assertSame('protected', $sheet->getCell('C1')->getStyle()->getProtection()->getHidden());
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Xml/XmlColumnRowHiddenTest.php | tests/PhpSpreadsheetTests/Reader/Xml/XmlColumnRowHiddenTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xml;
use PhpOffice\PhpSpreadsheet\Reader\Xml;
use PHPUnit\Framework\TestCase;
class XmlColumnRowHiddenTest extends TestCase
{
public function testColumnRowHidden(): void
{
$xmldata = <<< 'EOT'
<?xml version="1.0" encoding="UTF-8"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40">
<Worksheet ss:Name="1">
<ss:Table>
<Column ss:Hidden="1" />
<Column ss:Hidden="0" />
<Column />
<ss:Row ss:Hidden="1">
<ss:Cell>
<ss:Data ss:Type="String">hidden row and hidden column</ss:Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:Type="String">hidden row and visible column</ss:Data>
</ss:Cell>
</ss:Row>
<ss:Row ss:Hidden="0">
<ss:Cell>
<ss:Data ss:Type="String">visible row and hidden column</ss:Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:Type="String">visible row and visible column</ss:Data>
</ss:Cell>
</ss:Row>
<ss:Row />
</ss:Table>
</Worksheet>
</Workbook>
EOT;
$reader = new Xml();
$spreadsheet = $reader->loadSpreadsheetFromString($xmldata);
self::assertEquals(1, $spreadsheet->getSheetCount());
$sheet = $spreadsheet->getActiveSheet();
self::assertEquals('1', $sheet->getTitle());
self::assertFalse($sheet->getColumnDimension('A')->getVisible());
self::assertTrue($sheet->getColumnDimension('B')->getVisible());
self::assertTrue($sheet->getColumnDimension('C')->getVisible());
self::assertFalse($sheet->getRowDimension(1)->getVisible());
self::assertTrue($sheet->getRowDimension(2)->getVisible());
self::assertTrue($sheet->getRowDimension(3)->getVisible());
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Xml/XmlFilter.php | tests/PhpSpreadsheetTests/Reader/Xml/XmlFilter.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xml;
use PhpOffice\PhpSpreadsheet\Reader\IReadFilter;
/** Define a Read Filter class implementing IReadFilter */
class XmlFilter implements IReadFilter
{
public function readCell(string $columnAddress, int $row, string $worksheetName = ''): bool
{
return $row !== 4;
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Xml/XmlIssue4002Test.php | tests/PhpSpreadsheetTests/Reader/Xml/XmlIssue4002Test.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xml;
use PhpOffice\PhpSpreadsheet\Reader\Xml;
use PhpOffice\PhpSpreadsheet\Style\Border;
use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional;
class XmlIssue4002Test extends AbstractFunctional
{
private const XML_DATA = <<< 'EOT'
<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
<LastAuthor>Owen Leibman</LastAuthor>
<Created>2024-04-25T19:31:48Z</Created>
<Version>16.00</Version>
</DocumentProperties>
<OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">
<AllowPNG/>
</OfficeDocumentSettings>
<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
<WindowHeight>6510</WindowHeight>
<WindowWidth>19200</WindowWidth>
<WindowTopX>32767</WindowTopX>
<WindowTopY>32767</WindowTopY>
<ProtectStructure>False</ProtectStructure>
<ProtectWindows>False</ProtectWindows>
</ExcelWorkbook>
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Bottom"/>
<Borders/>
<Font ss:FontName="Aptos Narrow" x:Family="Swiss" ss:Size="11"
ss:Color="#000000"/>
<Interior/>
<NumberFormat/>
<Protection/>
</Style>
<Style ss:ID="s62">
<Alignment ss:Vertical="Bottom"/>
<Borders>
<Border ss:Position="Bottom" ss:LineStyle="Double" ss:Weight="3"/>
<Border ss:Position="Left" ss:LineStyle="Continuous"/>
<Border ss:Position="Right" ss:LineStyle="DashDot" ss:Weight="2"/>
<Border ss:Position="Top" ss:LineStyle="Dash" ss:Weight="1"/>
</Borders>
<Font ss:FontName="Aptos Narrow" x:Family="Swiss" ss:Size="11"
ss:Color="#000000" ss:Bold="1"/>
<Interior/>
<NumberFormat/>
<Protection/>
</Style>
</Styles>
<Worksheet ss:Name="Test">
<Table ss:ExpandedColumnCount="5" ss:ExpandedRowCount="4" x:FullColumns="1"
x:FullRows="1" ss:DefaultRowHeight="14.5">
<Row ss:AutoFitHeight="0"/>
<Row ss:AutoFitHeight="0" ss:Height="15">
<Cell ss:Index="2" ss:StyleID="s62"><Data ss:Type="String">TEST</Data></Cell>
<Cell ss:Index="5"><Data ss:Type="String">Vertical</Data></Cell>
</Row>
<Row ss:AutoFitHeight="0"/>
<Row ss:AutoFitHeight="0">
<Cell ss:Index="2"><Data ss:Type="String">New Page</Data></Cell>
<Cell ss:Index="5"><Data ss:Type="String">Last</Data></Cell>
</Row>
</Table>
<WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
<Unsynced/>
<Print>
<ValidPrinterInfo/>
<HorizontalResolution>600</HorizontalResolution>
<VerticalResolution>600</VerticalResolution>
</Print>
<ShowPageBreakZoom/>
<Zoom>200</Zoom>
<PageBreakZoom>200</PageBreakZoom>
<Selected/>
<Panes>
<Pane>
<Number>3</Number>
<ActiveRow>2</ActiveRow>
<ActiveCol>3</ActiveCol>
</Pane>
</Panes>
<ProtectObjects>False</ProtectObjects>
<ProtectScenarios>False</ProtectScenarios>
</WorksheetOptions>
<PageBreaks xmlns="urn:schemas-microsoft-com:office:excel">
<ColBreaks>
<ColBreak>
<Column>3</Column>
</ColBreak>
</ColBreaks>
<RowBreaks>
<RowBreak>
<Row>2</Row>
</RowBreak>
</RowBreaks>
</PageBreaks>
</Worksheet>
</Workbook>
EOT;
public function testZoomAndPageBreaks(): void
{
$reader = new Xml();
$spreadsheet = $reader->loadSpreadsheetFromString(self::XML_DATA);
self::assertEquals(1, $spreadsheet->getSheetCount());
$sheet = $spreadsheet->getActiveSheet();
self::assertEquals('Test', $sheet->getTitle());
self::assertSame(Border::BORDER_DOUBLE, $sheet->getStyle('B2')->getBorders()->getBottom()->getBorderStyle());
self::assertSame(Border::BORDER_MEDIUMDASHDOT, $sheet->getStyle('B2')->getBorders()->getRight()->getBorderStyle());
self::assertSame(Border::BORDER_DASHED, $sheet->getStyle('B2')->getBorders()->getTop()->getBorderStyle());
self::assertSame(Border::BORDER_HAIR, $sheet->getStyle('B2')->getBorders()->getLeft()->getBorderStyle());
self::assertSame(['A2'], array_keys($sheet->getRowBreaks()));
self::assertSame(['D1'], array_keys($sheet->getColumnBreaks()));
$sheetView = $sheet->getSheetView();
self::assertSame(200, $sheetView->getZoomScale());
self::assertSame(200, $sheetView->getZoomScaleNormal());
self::assertSame(100, $sheetView->getZoomScalePageLayoutView());
self::assertSame(200, $sheetView->getZoomScaleSheetLayoutView());
$spreadsheet->disconnectWorksheets();
}
public function testXlsxWriterAndReader(): void
{
$reader = new Xml();
$spreadsheet = $reader->loadSpreadsheetFromString(self::XML_DATA);
$reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx');
$spreadsheet->disconnectWorksheets();
$rsheet = $reloadedSpreadsheet->getActiveSheet();
self::assertSame(['A2'], array_keys($rsheet->getRowBreaks()));
self::assertSame(['D1'], array_keys($rsheet->getColumnBreaks()));
$rsheetView = $rsheet->getSheetView();
self::assertSame(200, $rsheetView->getZoomScale());
self::assertSame(200, $rsheetView->getZoomScaleNormal());
self::assertSame(100, $rsheetView->getZoomScalePageLayoutView());
self::assertSame(200, $rsheetView->getZoomScaleSheetLayoutView());
$reloadedSpreadsheet->disconnectWorksheets();
}
public function testXlsWriterAndReader(): void
{
$reader = new Xml();
$spreadsheet = $reader->loadSpreadsheetFromString(self::XML_DATA);
$reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xls');
$spreadsheet->disconnectWorksheets();
$rsheet = $reloadedSpreadsheet->getActiveSheet();
self::assertSame(['A2'], array_keys($rsheet->getRowBreaks()));
self::assertSame(['D1'], array_keys($rsheet->getColumnBreaks()));
$rsheetView = $rsheet->getSheetView();
self::assertSame(200, $rsheetView->getZoomScale());
self::assertSame(200, $rsheetView->getZoomScaleNormal());
self::assertSame(100, $rsheetView->getZoomScalePageLayoutView());
self::assertSame(100, $rsheetView->getZoomScaleSheetLayoutView(), 'different value than Xml or Xlsx but I do not see any consequence of that');
$reloadedSpreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Xml/XmlTest.php | tests/PhpSpreadsheetTests/Reader/Xml/XmlTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xml;
use PhpOffice\PhpSpreadsheet\Cell\DataType;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Reader\Exception as ReaderException;
use PhpOffice\PhpSpreadsheet\Reader\Xml;
use PHPUnit\Framework\TestCase;
class XmlTest extends TestCase
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerInvalidSimpleXML')]
public function testInvalidSimpleXML(string $filename): void
{
$xmlReader = new Xml();
$this->expectException(ReaderException::class);
$this->expectExceptionMessage('Invalid Spreadsheet file');
$xmlReader->load($filename);
}
public static function providerInvalidSimpleXML(): array
{
$tests = [];
$glob = glob('tests/data/Reader/Xml/XEETestInvalidSimpleXML*.xml');
self::assertNotFalse($glob);
foreach ($glob as $file) {
$tests[basename($file)] = [(string) realpath($file)];
}
return $tests;
}
/**
* Check if it can read XML Hyperlink correctly.
*/
public function testHyperlinksAltCharset(): void
{
$reader = new Xml();
$spreadsheet = $reader->load('tests/data/Reader/Xml/excel2003.iso8859-1.xml');
$firstSheet = $spreadsheet->getSheet(0);
self::assertSame('Voilà', $spreadsheet->getActiveSheet()->getCell('A1')->getValue());
$hyperlink = $firstSheet->getCell('A2');
self::assertEquals(DataType::TYPE_STRING, $hyperlink->getDataType());
self::assertEquals('PhpSpreadsheet', $hyperlink->getValue());
self::assertEquals('https://phpspreadsheet.readthedocs.io', $hyperlink->getHyperlink()->getUrl());
$spreadsheet->disconnectWorksheets();
}
public function testLoadCorruptedFile(): void
{
$this->expectException(ReaderException::class);
$this->expectExceptionMessage('Cannot load invalid XML file');
$xmlReader = new Xml();
$spreadsheet = @$xmlReader->load('tests/data/Reader/Xml/CorruptedXmlFile.xml');
}
public function testListWorksheetNamesCorruptedFile(): void
{
$this->expectException(ReaderException::class);
$this->expectExceptionMessage('Problem reading');
$xmlReader = new Xml();
$names = @$xmlReader->listWorksheetNames('tests/data/Reader/Xml/CorruptedXmlFile.xml');
self::assertNotEmpty($names);
}
public function testListWorksheetInfoCorruptedFile(): void
{
$this->expectException(ReaderException::class);
$this->expectExceptionMessage('Problem reading');
$xmlReader = new Xml();
$info = @$xmlReader->listWorksheetInfo('tests/data/Reader/Xml/CorruptedXmlFile.xml');
self::assertNotEmpty($info);
}
public function testInvalidXMLFromString(): void
{
$xmlReader = new Xml();
$this->expectException(ReaderException::class);
$this->expectExceptionMessage('Cannot load invalid XML string: 0');
$xmlReader->loadSpreadsheetFromString('0');
}
public function testInvalidXMLFromEmptyString(): void
{
$xmlReader = new Xml();
$this->expectException(ReaderException::class);
$this->expectExceptionMessage('Cannot load invalid XML string: ');
$xmlReader->loadSpreadsheetFromString('');
}
public function testEmptyFilename(): void
{
$xmlReader = new Xml();
$this->expectException(ReaderException::class);
$this->expectExceptionMessage('File "" does not exist');
$xmlReader->load('');
}
/**
* Ensures that a PHP warning for `Undefined array key "x"` is not triggered.
*
* Relies on PHPUnit's conversion of PHP warnings, deprecations, and notices to exceptions.
* If that warning occurs, the test should fail.
*/
public function testLoadXlsBug4669(): void
{
$filename = 'tests/data/Reader/Xml/bug4669.xml';
$reader = IOFactory::createReaderForFile($filename);
$reader->setReadDataOnly(true);
$spreadsheet = $reader->load($filename);
$sheet = $spreadsheet->getActiveSheet();
self::assertSame('Report Date', $sheet->getCell('A1')->getValue());
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Xml/XmlInfoTest.php | tests/PhpSpreadsheetTests/Reader/Xml/XmlInfoTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xml;
use PhpOffice\PhpSpreadsheet\Reader\Exception as ReaderException;
use PhpOffice\PhpSpreadsheet\Reader\Xml;
use PHPUnit\Framework\TestCase;
class XmlInfoTest extends TestCase
{
public function testListNames(): void
{
$filename = 'samples/templates/excel2003.xml';
$reader = new Xml();
$names = $reader->listWorksheetNames($filename);
self::assertCount(2, $names);
self::assertEquals('Sample Data', $names[0]);
self::assertEquals('Report Data', $names[1]);
}
public function testListNamesInvalidFile(): void
{
$this->expectException(ReaderException::class);
$this->expectExceptionMessage('Invalid Spreadsheet file');
$filename = __FILE__;
$reader = new Xml();
$names = $reader->listWorksheetNames($filename);
self::assertNotEquals($names, $names);
}
public function testListNamesGnumericFile(): void
{
$this->expectException(ReaderException::class);
$this->expectExceptionMessage('Invalid Spreadsheet file');
$filename = 'tests/data/Reader/Gnumeric/PageSetup.gnumeric.unzipped.xml';
$reader = new Xml();
$names = $reader->listWorksheetNames($filename);
self::assertNotEquals($names, $names);
}
public function testListInfo(): void
{
$filename = 'samples/templates/excel2003.xml';
$reader = new Xml();
$info = $reader->listWorksheetInfo($filename);
$expected = [
[
'worksheetName' => 'Sample Data',
'lastColumnLetter' => 'J',
'lastColumnIndex' => 9,
'totalRows' => 31,
'totalColumns' => 10,
'sheetState' => 'visible',
],
[
'worksheetName' => 'Report Data',
'lastColumnLetter' => 'I',
'lastColumnIndex' => 8,
'totalRows' => 15,
'totalColumns' => 9,
'sheetState' => 'visible',
],
];
self::assertEquals($expected, $info);
}
public function testListInfoInvalidFile(): void
{
$this->expectException(ReaderException::class);
$this->expectExceptionMessage('Invalid Spreadsheet file');
$filename = __FILE__;
$reader = new Xml();
$info = $reader->listWorksheetInfo($filename);
self::assertNotEquals($info, $info);
}
public function testListInfoGnumericFile(): void
{
$this->expectException(ReaderException::class);
$this->expectExceptionMessage('Invalid Spreadsheet file');
$filename = 'tests/data/Reader/Gnumeric/PageSetup.gnumeric.unzipped.xml';
$reader = new Xml();
$info = $reader->listWorksheetInfo($filename);
self::assertNotEquals($info, $info);
}
public function testLoadInvalidFile(): void
{
$this->expectException(ReaderException::class);
$this->expectExceptionMessage('Invalid Spreadsheet file');
$filename = __FILE__;
$reader = new Xml();
$spreadsheet = $reader->load($filename);
self::assertNotEquals($spreadsheet, $spreadsheet);
}
public function testLoadGnumericFile(): void
{
$this->expectException(ReaderException::class);
$this->expectExceptionMessage('Invalid Spreadsheet file');
$filename = 'tests/data/Reader/Gnumeric/PageSetup.gnumeric.unzipped.xml';
$reader = new Xml();
$spreadsheet = $reader->load($filename);
self::assertNotEquals($spreadsheet, $spreadsheet);
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Slk/SlkSharedFormulasTest.php | tests/PhpSpreadsheetTests/Reader/Slk/SlkSharedFormulasTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Slk;
use PhpOffice\PhpSpreadsheet\Reader\Slk;
class SlkSharedFormulasTest extends \PHPUnit\Framework\TestCase
{
public function testComments(): void
{
$testbook = 'tests/data/Reader/Slk/issue.2267c.slk';
$reader = new Slk();
$spreadsheet = $reader->load($testbook);
$sheet = $spreadsheet->getActiveSheet();
$range = 'A1:' . $sheet->getHighestDataColumn() . $sheet->getHighestDataRow();
$values = $sheet->RangeToArray($range, null, false, false, false, false); // just get values, don't calculate
$expected = [
[1, 10, 100, 101, 102],
['=A1+1', '=B1+1', '=C1+1', '=D1+1', '=E1+1'],
['=A2+1', '=B2+1', '=C2+1', '=D2+1', '=E2+1'],
['=A3+1', '=B3+1', '=C3+1', '=D3+1', '=E3+1'],
['=A4+1', '=B4+1', '=C4+1', '=D4+1', '=E4+1'],
];
self::assertSame($expected, $values);
$calcValues = $sheet->RangeToArray($range, null, true, false, false, false); // get calculated values
$expectedCalc = [
[1, 10, 100, 101, 102],
[2, 11, 101, 102, 103],
[3, 12, 102, 103, 104],
[4, 13, 103, 104, 105],
[5, 14, 104, 105, 106],
];
self::assertSame($expectedCalc, $calcValues);
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Slk/SlkCommentsTest.php | tests/PhpSpreadsheetTests/Reader/Slk/SlkCommentsTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Slk;
use PhpOffice\PhpSpreadsheet\Reader\Slk;
class SlkCommentsTest extends \PHPUnit\Framework\TestCase
{
public function testComments(): void
{
$testbook = 'tests/data/Reader/Slk/issue.2276.slk';
$reader = new Slk();
$spreadsheet = $reader->load($testbook);
$sheet = $spreadsheet->getActiveSheet();
$comments = $sheet->getComments();
self::assertCount(2, $comments);
self::assertArrayHasKey('A1', $comments);
self::assertArrayHasKey('B2', $comments);
self::assertSame("Zeratul:\nEn Taro Adun!", $sheet->getComment('A1')->getText()->getPlainText());
self::assertSame("Arthas:\nFrostmourne Hungers.", $sheet->getComment('B2')->getText()->getPlainText());
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Slk/BinderTest.php | tests/PhpSpreadsheetTests/Reader/Slk/BinderTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Slk;
use PhpOffice\PhpSpreadsheet\Cell\StringValueBinder;
use PhpOffice\PhpSpreadsheet\Reader\Slk;
use PHPUnit\Framework\TestCase;
class BinderTest extends TestCase
{
public function testBinder(): void
{
$infile = 'tests/data/Reader/Slk/issue.2276.slk';
$reader = new Slk();
$spreadsheet = $reader->load($infile);
$sheet = $spreadsheet->getActiveSheet();
$expected1 = [[1, 2], [3, '']];
self::assertSame($expected1, $sheet->toArray(null, false, false));
$reader2 = new Slk();
$reader2->setValueBinder(new StringValueBinder());
$spreadsheet2 = $reader2->load($infile);
$sheet2 = $spreadsheet2->getActiveSheet();
$expected2 = [['1', '2'], ['3', '']];
self::assertSame($expected2, $sheet2->toArray(null, false, false));
$spreadsheet->disconnectWorksheets();
$spreadsheet2->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Slk/SlkTest.php | tests/PhpSpreadsheetTests/Reader/Slk/SlkTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Slk;
use PhpOffice\PhpSpreadsheet\Reader\Exception as ReaderException;
use PhpOffice\PhpSpreadsheet\Reader\Slk;
use PhpOffice\PhpSpreadsheet\Shared\File;
use PhpOffice\PhpSpreadsheet\Style\Border;
use PhpOffice\PhpSpreadsheet\Style\Fill;
use PhpOffice\PhpSpreadsheet\Style\Font;
class SlkTest extends \PHPUnit\Framework\TestCase
{
private static string $testbook = __DIR__ . '/../../../../samples/templates/SylkTest.slk';
private string $filename = '';
protected function teardown(): void
{
if ($this->filename !== '') {
unlink($this->filename);
$this->filename = '';
}
}
public function testInfo(): void
{
$reader = new Slk();
$workSheetInfo = $reader->listWorkSheetInfo(self::$testbook);
self::assertCount(1, $workSheetInfo);
$info0 = $workSheetInfo[0];
self::assertSame('SylkTest', $info0['worksheetName']);
self::assertSame('J', $info0['lastColumnLetter']);
self::assertSame(9, $info0['lastColumnIndex']);
self::assertSame(18, $info0['totalRows']);
self::assertSame(10, $info0['totalColumns']);
self::assertSame(['SylkTest'], $reader->listWorksheetNames(self::$testbook));
}
public function testBadFileName(): void
{
$this->expectException(ReaderException::class);
$reader = new Slk();
self::assertNull($reader->setLoadSheetsOnly(null)->getLoadSheetsOnly());
$reader->listWorkSheetInfo(self::$testbook . 'xxx');
}
public function testBadFileName2(): void
{
$reader = new Slk();
self::assertFalse($reader->canRead(self::$testbook . 'xxx'));
}
public function testNotSylkFile(): void
{
$this->expectException(ReaderException::class);
$reader = new Slk();
$reader->listWorkSheetInfo(__FILE__);
}
public function testLoadSlk(): void
{
$reader = new Slk();
$spreadsheet = $reader->load(self::$testbook);
$sheet = $spreadsheet->getActiveSheet();
self::assertEquals('SylkTest', $sheet->getTitle());
self::assertEquals('FFFF0000', $sheet->getCell('A1')->getStyle()->getFont()->getColor()->getARGB());
self::assertEquals(Fill::FILL_PATTERN_GRAY125, $sheet->getCell('A2')->getStyle()->getFill()->getFillType());
self::assertEquals(Font::UNDERLINE_SINGLE, $sheet->getCell('A4')->getStyle()->getFont()->getUnderline());
self::assertEquals('Test with (;) in string', $sheet->getCell('A4')->getValue());
self::assertEquals(22269, $sheet->getCell('A10')->getValue());
self::assertEquals('dd/mm/yyyy', $sheet->getCell('A10')->getStyle()->getNumberFormat()->getFormatCode());
self::assertEquals('19/12/1960', $sheet->getCell('A10')->getFormattedValue());
self::assertEquals(1.5, $sheet->getCell('A11')->getValue());
self::assertEquals('# ?/?', $sheet->getCell('A11')->getStyle()->getNumberFormat()->getFormatCode());
self::assertEquals('1 1/2', $sheet->getCell('A11')->getFormattedValue());
self::assertEquals('=B1+C1', $sheet->getCell('H1')->getValue());
self::assertEquals('=E2&F2', $sheet->getCell('J2')->getValue());
self::assertEquals('=SUM(C1:C4)', $sheet->getCell('I5')->getValue());
self::assertEquals('=MEDIAN(B6:B8)', $sheet->getCell('B9')->getValue());
self::assertEquals(11, $sheet->getCell('E1')->getStyle()->getFont()->getSize());
self::assertTrue($sheet->getCell('E1')->getStyle()->getFont()->getBold());
self::assertTrue($sheet->getCell('E1')->getStyle()->getFont()->getItalic());
self::assertEquals(Font::UNDERLINE_SINGLE, $sheet->getCell('E1')->getStyle()->getFont()->getUnderline());
self::assertFalse($sheet->getCell('E2')->getStyle()->getFont()->getBold());
self::assertFalse($sheet->getCell('E2')->getStyle()->getFont()->getItalic());
self::assertEquals(Font::UNDERLINE_NONE, $sheet->getCell('E2')->getStyle()->getFont()->getUnderline());
self::assertTrue($sheet->getCell('E3')->getStyle()->getFont()->getBold());
self::assertFalse($sheet->getCell('E3')->getStyle()->getFont()->getItalic());
self::assertEquals(Font::UNDERLINE_NONE, $sheet->getCell('E3')->getStyle()->getFont()->getUnderline());
self::assertFalse($sheet->getCell('E4')->getStyle()->getFont()->getBold());
self::assertTrue($sheet->getCell('E4')->getStyle()->getFont()->getItalic());
self::assertEquals(Font::UNDERLINE_NONE, $sheet->getCell('E4')->getStyle()->getFont()->getUnderline());
self::assertTrue($sheet->getCell('F1')->getStyle()->getFont()->getBold());
self::assertFalse($sheet->getCell('F1')->getStyle()->getFont()->getItalic());
self::assertEquals(Font::UNDERLINE_SINGLE, $sheet->getCell('F1')->getStyle()->getFont()->getUnderline());
self::assertFalse($sheet->getCell('F2')->getStyle()->getFont()->getBold());
self::assertFalse($sheet->getCell('F2')->getStyle()->getFont()->getItalic());
self::assertEquals(Font::UNDERLINE_NONE, $sheet->getCell('F2')->getStyle()->getFont()->getUnderline());
self::assertTrue($sheet->getCell('F3')->getStyle()->getFont()->getBold());
self::assertTrue($sheet->getCell('F3')->getStyle()->getFont()->getItalic());
self::assertEquals(Font::UNDERLINE_NONE, $sheet->getCell('F3')->getStyle()->getFont()->getUnderline());
self::assertFalse($sheet->getCell('F4')->getStyle()->getFont()->getBold());
self::assertFalse($sheet->getCell('F4')->getStyle()->getFont()->getItalic());
self::assertEquals(Font::UNDERLINE_NONE, $sheet->getCell('F4')->getStyle()->getFont()->getUnderline());
self::assertEquals(Border::BORDER_THIN, $sheet->getCell('C10')->getStyle()->getBorders()->getTop()->getBorderStyle());
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C10')->getStyle()->getBorders()->getRight()->getBorderStyle());
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C10')->getStyle()->getBorders()->getBottom()->getBorderStyle());
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C10')->getStyle()->getBorders()->getLeft()->getBorderStyle());
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C12')->getStyle()->getBorders()->getTop()->getBorderStyle());
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C12')->getStyle()->getBorders()->getRight()->getBorderStyle());
self::assertEquals(Border::BORDER_THIN, $sheet->getCell('C12')->getStyle()->getBorders()->getBottom()->getBorderStyle());
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C12')->getStyle()->getBorders()->getLeft()->getBorderStyle());
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C14')->getStyle()->getBorders()->getTop()->getBorderStyle());
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C14')->getStyle()->getBorders()->getRight()->getBorderStyle());
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C14')->getStyle()->getBorders()->getBottom()->getBorderStyle());
self::assertEquals(Border::BORDER_THIN, $sheet->getCell('C14')->getStyle()->getBorders()->getLeft()->getBorderStyle());
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C16')->getStyle()->getBorders()->getTop()->getBorderStyle());
self::assertEquals(Border::BORDER_THIN, $sheet->getCell('C16')->getStyle()->getBorders()->getRight()->getBorderStyle());
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C16')->getStyle()->getBorders()->getBottom()->getBorderStyle());
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C16')->getStyle()->getBorders()->getLeft()->getBorderStyle());
self::assertEquals(Border::BORDER_THIN, $sheet->getCell('C18')->getStyle()->getBorders()->getTop()->getBorderStyle());
self::assertEquals(Border::BORDER_THIN, $sheet->getCell('C18')->getStyle()->getBorders()->getRight()->getBorderStyle());
self::assertEquals(Border::BORDER_THIN, $sheet->getCell('C18')->getStyle()->getBorders()->getBottom()->getBorderStyle());
self::assertEquals(Border::BORDER_THIN, $sheet->getCell('C18')->getStyle()->getBorders()->getLeft()->getBorderStyle());
// Have not yet figured out how C6/C7 are centred
$spreadsheet->disconnectWorksheets();
}
public function testSheetIndex(): void
{
$reader = new Slk();
$sheetIndex = 2;
$reader->setSheetIndex($sheetIndex);
self::assertEquals($sheetIndex, $reader->getSheetIndex());
$spreadsheet = $reader->load(self::$testbook);
$sheet = $spreadsheet->setActiveSheetIndex($sheetIndex);
self::assertEquals('SylkTest', $sheet->getTitle());
self::assertEquals('FFFF0000', $sheet->getCell('A1')->getStyle()->getFont()->getColor()->getARGB());
$spreadsheet->disconnectWorksheets();
}
public function testLongName(): void
{
$contents = file_get_contents(self::$testbook);
$this->filename = File::sysGetTempDir()
. '/123456789a123456789b123456789c12345.slk';
file_put_contents($this->filename, $contents);
$reader = new Slk();
$names = $reader->listWorksheetNames($this->filename);
// Following ignored, just make sure it's executable.
$reader->setLoadSheetsOnly([$names[0]]);
$spreadsheet = $reader->load($this->filename);
$sheet = $spreadsheet->getActiveSheet();
self::assertEquals('123456789a123456789b123456789c1', $sheet->getTitle());
self::assertEquals('FFFF0000', $sheet->getCell('A1')->getStyle()->getFont()->getColor()->getARGB());
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Html/HtmlBorderTest.php | tests/PhpSpreadsheetTests/Reader/Html/HtmlBorderTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Html;
use PhpOffice\PhpSpreadsheet\Reader\Html;
use PhpOffice\PhpSpreadsheet\Style\Border;
use PHPUnit\Framework\TestCase;
class HtmlBorderTest extends TestCase
{
public function testCanApplyInlineBordersStyles(): void
{
$html = '<table>
<tr>
<td style="border: 1px solid #333333;">Thin border</td>
<td style="border-bottom: 1px dashed #333333;">Border bottom</td>
<td style="border-top: 1px solid #333333;">Border top</td>
<td style="border-left: 1px solid green;">Border left</td>
<td style="border-right: 1px solid #333333;">Border right</td>
<td style="border: none"></td>
<td style="border: dashed;"></td>
<td style="border: dotted #333333;"></td>
</tr>
</table>';
$spreadsheet = HtmlHelper::loadHtmlStringIntoSpreadsheet($html);
$firstSheet = $spreadsheet->getSheet(0);
$style = $firstSheet->getCell('A1')->getStyle();
$borders = $style->getBorders();
/** @var Border $border */
foreach ([$borders->getTop(), $borders->getBottom(), $borders->getLeft(), $borders->getRight()] as $border) {
self::assertEquals('333333', $border->getColor()->getRGB());
self::assertEquals(Border::BORDER_THIN, $border->getBorderStyle());
}
$style = $firstSheet->getCell('B1')->getStyle();
$border = $style->getBorders()->getBottom();
self::assertEquals('333333', $border->getColor()->getRGB());
self::assertEquals(Border::BORDER_DASHED, $border->getBorderStyle());
self::assertEquals(Border::BORDER_NONE, $style->getBorders()->getTop()->getBorderStyle());
$style = $firstSheet->getCell('C1')->getStyle();
$border = $style->getBorders()->getTop();
self::assertEquals('333333', $border->getColor()->getRGB());
self::assertEquals(Border::BORDER_THIN, $border->getBorderStyle());
self::assertEquals(Border::BORDER_NONE, $style->getBorders()->getBottom()->getBorderStyle());
$style = $firstSheet->getCell('D1')->getStyle();
$border = $style->getBorders()->getLeft();
self::assertEquals('00ff00', $border->getColor()->getRGB());
self::assertEquals(Border::BORDER_THIN, $border->getBorderStyle());
self::assertEquals(Border::BORDER_NONE, $style->getBorders()->getBottom()->getBorderStyle());
$style = $firstSheet->getCell('E1')->getStyle();
$border = $style->getBorders()->getRight();
self::assertEquals('333333', $border->getColor()->getRGB());
self::assertEquals(Border::BORDER_THIN, $border->getBorderStyle());
self::assertEquals(Border::BORDER_NONE, $style->getBorders()->getBottom()->getBorderStyle());
$style = $firstSheet->getCell('F1')->getStyle();
$borders = $style->getBorders();
foreach ([$borders->getTop(), $borders->getBottom(), $borders->getLeft(), $borders->getRight()] as $border) {
self::assertEquals(Border::BORDER_NONE, $border->getBorderStyle());
}
$style = $firstSheet->getCell('G1')->getStyle();
$borders = $style->getBorders();
$border = $borders->getRight();
self::assertEquals(Border::BORDER_DASHED, $border->getBorderStyle());
$style = $firstSheet->getCell('H1')->getStyle();
$borders = $style->getBorders();
$border = $borders->getRight();
self::assertEquals(Border::BORDER_DOTTED, $border->getBorderStyle());
self::assertEquals('333333', $border->getColor()->getRGB());
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerBorderStyle')]
public function testBorderStyle(string $style, string $expectedResult): void
{
$borders = Html::getBorderMappings();
self::assertEquals($expectedResult, $borders[$style]);
}
public function testBorderStyleCoverage(): void
{
$expected = Html::getBorderMappings();
$covered = [];
foreach ($expected as $key => $val) {
$covered[$key] = 0;
}
$tests = $this->providerBorderStyle();
foreach ($tests as $test) {
/** @var array<int, int|string> $test */
$covered[$test[0]] = 1;
}
foreach ($covered as $key => $val) {
self::assertEquals(1, $val, "Borderstyle $key not tested");
}
}
public static function providerBorderStyle(): array
{
return [
['dash-dot', Border::BORDER_DASHDOT],
['dash-dot-dot', Border::BORDER_DASHDOTDOT],
['dashed', Border::BORDER_DASHED],
['dotted', Border::BORDER_DOTTED],
['double', Border::BORDER_DOUBLE],
['hair', Border::BORDER_HAIR],
['medium', Border::BORDER_MEDIUM],
['medium-dashed', Border::BORDER_MEDIUMDASHED],
['medium-dash-dot', Border::BORDER_MEDIUMDASHDOT],
['medium-dash-dot-dot', Border::BORDER_MEDIUMDASHDOTDOT],
['none', Border::BORDER_NONE],
['slant-dash-dot', Border::BORDER_SLANTDASHDOT],
['solid', Border::BORDER_THIN],
['thick', Border::BORDER_THICK],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Html/Issue2810Test.php | tests/PhpSpreadsheetTests/Reader/Html/Issue2810Test.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Html;
use PhpOffice\PhpSpreadsheet\Reader\Html;
use PHPUnit\Framework\TestCase;
class Issue2810Test extends TestCase
{
// Reader has been converting falsey values to null
public function testIssue2810(): void
{
$content = <<<'EOF'
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>Declaracion en Linea</title>
</head>
<body>
<table>
<tr>
<td>1</td>
<td>0</td>
<td>2</td>
</tr>
</table>
</body>
</html>
EOF;
$reader = new Html();
$spreadsheet = $reader->loadFromString($content);
$sheet = $spreadsheet->getActiveSheet();
self::assertSame(1, $sheet->getCell('A1')->getValue());
self::assertSame(0, $sheet->getCell('B1')->getValue());
self::assertSame(2, $sheet->getCell('C1')->getValue());
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Html/Issue1284Test.php | tests/PhpSpreadsheetTests/Reader/Html/Issue1284Test.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Html;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional;
class Issue1284Test extends AbstractFunctional
{
public function testIssue1284(): void
{
$ideographicSpace = "\u{3000}";
$nbsp = "\u{a0}";
$spreadsheetOld = new Spreadsheet();
$osheet = $spreadsheetOld->getActiveSheet();
$osheet->getCell('A1')->setValue('# item 1');
$osheet->getCell('A2')->setValue("$ideographicSpace# item 2");
$osheet->getCell('A3')->setValue("$ideographicSpace$ideographicSpace# item 3");
$osheet->getCell('A4')->setValue("$nbsp# item\t4");
$osheet->getCell('A5')->setValue("$nbsp$nbsp# item 5");
$spreadsheet = $this->writeAndReload($spreadsheetOld, 'Html');
$spreadsheetOld->disconnectWorksheets();
$sheet = $spreadsheet->getActiveSheet();
self::assertSame('# item 1', $sheet->getCell('A1')->getValue(), 'nothing changed');
self::assertSame("$ideographicSpace# item 2", $sheet->getCell('A2')->getValue(), 'nothing changed including 1 ideographic space');
self::assertSame("$ideographicSpace$ideographicSpace# item 3", $sheet->getCell('A3')->getValue(), 'nothing changed including 2 ideographic spaces');
self::assertSame("$nbsp# item 4", $sheet->getCell('A4')->getValue(), 'nbsp unchanged, 2 spaces reduced to 1, tab changed to space');
self::assertSame("$nbsp$nbsp# item 5", $sheet->getCell('A5')->getValue(), 'many spaces reduced to 1');
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Html/DirectionTest.php | tests/PhpSpreadsheetTests/Reader/Html/DirectionTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Html;
use PhpOffice\PhpSpreadsheet\Reader\Html as HtmlReader;
use PHPUnit\Framework\TestCase;
class DirectionTest extends TestCase
{
public function testRtl(): void
{
$inlines = [
"<table border='0' cellpadding='0' cellspacing='0' dir='rtl' id='sheet0' class='sheet0 gridlines'>",
'<tbody>',
'<tr class="row0">',
'<td class="column0 style0 s">a1</td>',
'<td class="column1 style0 s">b1</td>',
'<td class="column2 style0 s">c1</td>',
'</tr>',
'<tr class="row1">',
'<td class="column0 style0 s">a2</td>',
'<td class="column1 style0 s">b2</td>',
'<td class="column2 style0 s">c2</td>',
'</tr>',
'</tbody></table>',
];
$html = implode("\n", $inlines);
$reader = new HtmlReader();
$spreadsheet = $reader->loadFromString($html);
$sheet = $spreadsheet->getActiveSheet();
self::assertTrue($sheet->getRightToLeft());
self::assertSame('a1', $sheet->getCell('A1')->getValue());
self::assertSame('c2', $sheet->getCell('C2')->getValue());
$spreadsheet->disconnectWorksheets();
}
public function testLtr(): void
{
$inlines = [
"<table border='0' cellpadding='0' cellspacing='0' dir='ltr' id='sheet0' class='sheet0 gridlines'>",
'<tbody>',
'<tr class="row0">',
'<td class="column0 style0 s">a1</td>',
'<td class="column1 style0 s">b1</td>',
'<td class="column2 style0 s">c1</td>',
'</tr>',
'<tr class="row1">',
'<td class="column0 style0 s">a2</td>',
'<td class="column1 style0 s">b2</td>',
'<td class="column2 style0 s">c2</td>',
'</tr>',
'</tbody></table>',
];
$html = implode("\n", $inlines);
$reader = new HtmlReader();
$spreadsheet = $reader->loadFromString($html);
$sheet = $spreadsheet->getActiveSheet();
self::assertFalse($sheet->getRightToLeft());
self::assertSame('a1', $sheet->getCell('A1')->getValue());
self::assertSame('c2', $sheet->getCell('C2')->getValue());
$spreadsheet->disconnectWorksheets();
}
public function testDefault(): void
{
$inlines = [
"<table border='0' cellpadding='0' cellspacing='0' id='sheet0' class='sheet0 gridlines'>",
'<tbody>',
'<tr class="row0">',
'<td class="column0 style0 s">a1</td>',
'<td class="column1 style0 s">b1</td>',
'<td class="column2 style0 s">c1</td>',
'</tr>',
'<tr class="row1">',
'<td class="column0 style0 s">a2</td>',
'<td class="column1 style0 s">b2</td>',
'<td class="column2 style0 s">c2</td>',
'</tr>',
'</tbody></table>',
];
$html = implode("\n", $inlines);
$reader = new HtmlReader();
$spreadsheet = $reader->loadFromString($html);
$sheet = $spreadsheet->getActiveSheet();
self::assertFalse($sheet->getRightToLeft());
self::assertSame('a1', $sheet->getCell('A1')->getValue());
self::assertSame('c2', $sheet->getCell('C2')->getValue());
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Html/Issue2029Test.php | tests/PhpSpreadsheetTests/Reader/Html/Issue2029Test.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Html;
use PhpOffice\PhpSpreadsheet\Reader\Html;
use PHPUnit\Framework\TestCase;
class Issue2029Test extends TestCase
{
public function testIssue2029(): void
{
$content = <<<'EOF'
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>Declaracion en Linea</title>
</head>
<body>
<table>
<tr>
<td>
<table>
<tr>
<td>
<table>
<tbody>
<tr>
<td>CUIT:</td>
<td><label id="lblCUIT" class="text-left">30-53914190-9</label></td>
</tr>
<tr>
<td>Período</td>
<td><label id="lblPeriodo" class="text-left">02 2021</label></td>
</tr>
<tr>
<td>Secuencia:</td>
<td><label id="lblSecuencia" class="text-left">0 - Original</label></td>
</tr>
<tr>
<td>Contribuyente:</td>
<td><label id="lblContribuyente">SIND DE TRABAJADORES DE IND DE LA ALIMENTACION</label></td>
<td><label id="lblFechaHoy"></label></td>
</tr>
</tbody>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table border="1px">
<tr>
<th class="text-center">
CUIL
</th>
<th class="text-center">
Apellido y Nombre
</th>
<th class="text-center">
Obra Social
</th>
<th class="text-center">
Corresponde Reducción?
</th>
</tr>
<tr>
<td class="text-center">
12345678901
</td>
<td class="text-center">
EMILIANO ZAPATA SALAZAR
</td>
<td class="text-center">
101208
</td>
<td class="text-center">
Yes
</td>
</tr>
<tr>
<td class="text-center">
23456789012
</td>
<td class="text-center">
FRANCISCO PANCHO VILLA
</td>
<td class="text-center">
101208
</td>
<td class="text-center">
No
</td>
</tr>
</table>
</body>
</html>
EOF;
$reader = new Html();
$spreadsheet = $reader->loadFromString($content);
$sheet = $spreadsheet->getActiveSheet();
self::assertSame('CUIT:', $sheet->getCell('A1')->getValue());
self::assertSame('30-53914190-9', $sheet->getCell('B1')->getValue());
self::assertSame('Contribuyente:', $sheet->getCell('A4')->getValue());
self::assertSame('Apellido y Nombre', $sheet->getCell('B9')->getValue());
self::assertEquals('101208', $sheet->getCell('C10')->getValue());
self::assertEquals('Yes', $sheet->getCell('D10')->getValue());
self::assertEquals('23456789012', $sheet->getCell('A11')->getValue());
self::assertEquals('No', $sheet->getCell('D11')->getValue());
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Html/ViewportTest.php | tests/PhpSpreadsheetTests/Reader/Html/ViewportTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Html;
use PhpOffice\PhpSpreadsheet\Document\Properties;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional;
class ViewportTest extends AbstractFunctional
{
public function testViewport(): void
{
$spreadsheetOld = new Spreadsheet();
$spreadsheetOld->getProperties()->setViewport(Properties::SUGGESTED_VIEWPORT);
$osheet = $spreadsheetOld->getActiveSheet();
$osheet->getCell('A1')->setValue(1);
$spreadsheet = $this->writeAndReload($spreadsheetOld, 'Html');
$spreadsheetOld->disconnectWorksheets();
$sheet = $spreadsheet->getActiveSheet();
self::assertSame(1, $sheet->getCell('A1')->getValue());
self::assertSame('width=device-width, initial-scale=1', $spreadsheet->getProperties()->getViewport());
$spreadsheet->disconnectWorksheets();
}
public function testNoViewport(): void
{
$spreadsheetOld = new Spreadsheet();
//$spreadsheetOld->getProperties()->setViewport(SUGGESTED_VIEWPORT);
$osheet = $spreadsheetOld->getActiveSheet();
$osheet->getCell('A1')->setValue(1);
$spreadsheet = $this->writeAndReload($spreadsheetOld, 'Html');
$spreadsheetOld->disconnectWorksheets();
$sheet = $spreadsheet->getActiveSheet();
self::assertSame(1, $sheet->getCell('A1')->getValue());
self::assertSame('', $spreadsheet->getProperties()->getViewport());
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Html/HtmlTest.php | tests/PhpSpreadsheetTests/Reader/Html/HtmlTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Html;
use PhpOffice\PhpSpreadsheet\Cell\DataType;
use PhpOffice\PhpSpreadsheet\Reader\Exception as ReaderException;
use PhpOffice\PhpSpreadsheet\Reader\Html;
use PhpOffice\PhpSpreadsheet\Style\Alignment;
use PhpOffice\PhpSpreadsheet\Style\Border;
use PhpOffice\PhpSpreadsheet\Style\Font;
use PHPUnit\Framework\TestCase;
class HtmlTest extends TestCase
{
public function testCsvWithAngleBracket(): void
{
$filename = 'tests/data/Reader/HTML/csv_with_angle_bracket.csv';
$reader = new Html();
self::assertFalse($reader->canRead($filename));
}
// testBadHtml moved to HtmlPhpunit10Test
public function testNonHtml(): void
{
$filename = __FILE__;
$reader = new Html();
self::assertFalse($reader->canRead($filename));
$this->expectException(ReaderException::class);
$reader->load($filename);
}
public function testInvalidFilename(): void
{
$reader = new Html();
self::assertEquals(0, $reader->getSheetIndex());
self::assertFalse($reader->canRead(''));
}
public static function providerCanReadVerySmallFile(): array
{
$padding = str_repeat('a', 2048);
return [
[true, ' <html> ' . $padding . ' </html> '],
[true, ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html>' . $padding . '</html>'],
[true, '<html></html>'],
[false, ''],
];
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerCanReadVerySmallFile')]
public function testCanReadVerySmallFile(bool $expected, string $content): void
{
$filename = HtmlHelper::createHtml($content);
$reader = new Html();
$actual = $reader->canRead($filename);
self::assertSame($expected, $actual);
unlink($filename);
}
public function testBackgroundColorInRanding(): void
{
$html = '<table>
<tr>
<td style="background-color: #0000FF;color: #FFFFFF">Blue background</td>
<td style="background-color: unknown1;color: unknown2">Unknown fore/background</td>
<td style="background-color: antiquewhite2;color: aliceblue">Unknown fore/background</td>
</tr>
</table>';
$spreadsheet = HtmlHelper::loadHtmlStringIntoSpreadsheet($html);
$firstSheet = $spreadsheet->getSheet(0);
$style = $firstSheet->getCell('A1')->getStyle();
self::assertEquals('FFFFFF', $style->getFont()->getColor()->getRGB());
self::assertEquals('0000FF', $style->getFill()->getStartColor()->getRGB());
self::assertEquals('0000FF', $style->getFill()->getEndColor()->getRGB());
$style = $firstSheet->getCell('B1')->getStyle();
self::assertEquals('000000', $style->getFont()->getColor()->getRGB());
self::assertEquals('000000', $style->getFill()->getEndColor()->getRGB());
self::assertEquals('FFFFFF', $style->getFill()->getstartColor()->getRGB());
$style = $firstSheet->getCell('C1')->getStyle();
self::assertEquals('f0f8ff', $style->getFont()->getColor()->getRGB());
self::assertEquals('eedfcc', $style->getFill()->getEndColor()->getRGB());
self::assertEquals('eedfcc', $style->getFill()->getstartColor()->getRGB());
$spreadsheet->disconnectWorksheets();
}
public function testCanApplyInlineFontStyles(): void
{
$html = '<table>
<tr>
<td style="font-size: 16px;">16px</td>
<td style="font-family: \'Times New Roman\'">Times New Roman</td>
<td style="font-weight: bold;">Bold</td>
<td style="font-style: italic;">Italic</td>
<td style="text-decoration: underline;">Underline</td>
<td style="text-decoration: line-through;">Line through</td>
</tr>
</table>';
$spreadsheet = HtmlHelper::loadHtmlStringIntoSpreadsheet($html);
$firstSheet = $spreadsheet->getSheet(0);
$style = $firstSheet->getCell('A1')->getStyle();
self::assertEquals(16, $style->getFont()->getSize());
$style = $firstSheet->getCell('B1')->getStyle();
self::assertEquals('Times New Roman', $style->getFont()->getName());
$style = $firstSheet->getCell('C1')->getStyle();
self::assertTrue($style->getFont()->getBold());
$style = $firstSheet->getCell('D1')->getStyle();
self::assertTrue($style->getFont()->getItalic());
$style = $firstSheet->getCell('E1')->getStyle();
self::assertEquals(Font::UNDERLINE_SINGLE, $style->getFont()->getUnderline());
$style = $firstSheet->getCell('F1')->getStyle();
self::assertTrue($style->getFont()->getStrikethrough());
$spreadsheet->disconnectWorksheets();
}
public function testCanApplyInlineWidth(): void
{
$html = '<table>
<tr>
<td width="50">50px</td>
<td style="width: 100px;">100px</td>
<td width="50px">50px</td>
</tr>
</table>';
$spreadsheet = HtmlHelper::loadHtmlStringIntoSpreadsheet($html);
$firstSheet = $spreadsheet->getSheet(0);
$dimension = $firstSheet->getColumnDimension('A');
self::assertEquals(50, $dimension->getWidth());
$dimension = $firstSheet->getColumnDimension('B');
self::assertEquals(100, $dimension->getWidth('px'));
$dimension = $firstSheet->getColumnDimension('C');
self::assertEquals(50, $dimension->getWidth('px'));
$spreadsheet->disconnectWorksheets();
}
public function testCanApplyInlineHeight(): void
{
$html = '<table>
<tr>
<td height="50">1</td>
</tr>
<tr>
<td style="height: 100px;">2</td>
</tr>
<tr>
<td height="50px">1</td>
</tr>
</table>';
$spreadsheet = HtmlHelper::loadHtmlStringIntoSpreadsheet($html);
$firstSheet = $spreadsheet->getSheet(0);
$dimension = $firstSheet->getRowDimension(1);
self::assertEquals(50, $dimension->getRowHeight());
$dimension = $firstSheet->getRowDimension(2);
self::assertEquals(100, $dimension->getRowHeight('px'));
$dimension = $firstSheet->getRowDimension(3);
self::assertEquals(50, $dimension->getRowHeight('px'));
$spreadsheet->disconnectWorksheets();
}
public function testCanApplyAlignment(): void
{
$html = '<table>
<tr>
<td align="center">Center align</td>
<td valign="center">Center valign</td>
<td style="text-align: center;">Center align</td>
<td style="vertical-align: center;">Center valign</td>
<td style="text-indent: 9px;">Text indent</td>
<td style="word-wrap: break-word;">Wraptext</td>
</tr>
</table>';
$spreadsheet = HtmlHelper::loadHtmlStringIntoSpreadsheet($html);
$firstSheet = $spreadsheet->getSheet(0);
$style = $firstSheet->getCell('A1')->getStyle();
self::assertEquals(Alignment::HORIZONTAL_CENTER, $style->getAlignment()->getHorizontal());
$style = $firstSheet->getCell('B1')->getStyle();
self::assertEquals(Alignment::VERTICAL_CENTER, $style->getAlignment()->getVertical());
$style = $firstSheet->getCell('C1')->getStyle();
self::assertEquals(Alignment::HORIZONTAL_CENTER, $style->getAlignment()->getHorizontal());
$style = $firstSheet->getCell('D1')->getStyle();
self::assertEquals(Alignment::VERTICAL_CENTER, $style->getAlignment()->getVertical());
$style = $firstSheet->getCell('E1')->getStyle();
self::assertEquals(1, $style->getAlignment()->getIndent());
$style = $firstSheet->getCell('F1')->getStyle();
self::assertTrue($style->getAlignment()->getWrapText());
$spreadsheet->disconnectWorksheets();
}
public function testCanApplyInlineDataFormat(): void
{
$html = '<table>
<tr>
<td data-format="mmm-yy">2019-02-02 12:34:00</td>
<td data-format="#.000">3</td>
<td data-format="#.000">x</td>
</tr>
</table>';
$spreadsheet = HtmlHelper::loadHtmlStringIntoSpreadsheet($html);
$sheet = $spreadsheet->getSheet(0);
self::assertEquals('mmm-yy', $sheet->getStyle('A1')->getNumberFormat()->getFormatCode());
self::assertEquals('2019-02-02 12:34:00', $sheet->getCell('A1')->getFormattedValue(), 'field is string not number so not formatted');
self::assertEquals('#.000', $sheet->getStyle('B1')->getNumberFormat()->getFormatCode());
self::assertEquals('3.000', $sheet->getCell('B1')->getFormattedValue(), 'format applied to numeric value');
self::assertEquals('#.000', $sheet->getStyle('C1')->getNumberFormat()->getFormatCode());
self::assertEquals('x', $sheet->getCell('C1')->getFormattedValue(), 'format not applied to non-numeric value');
$spreadsheet->disconnectWorksheets();
}
public function testCanApplyCellWrapping(): void
{
$html = '<table>
<tr>
<td>Hello World</td>
</tr>
<tr>
<td>Hello<br />World</td>
</tr>
<tr>
<td>Hello<br>World</td>
</tr>
</table>';
$spreadsheet = HtmlHelper::loadHtmlStringIntoSpreadsheet($html);
$firstSheet = $spreadsheet->getSheet(0);
$cellStyle = $firstSheet->getStyle('A1');
self::assertFalse($cellStyle->getAlignment()->getWrapText());
$cellStyle = $firstSheet->getStyle('A2');
self::assertTrue($cellStyle->getAlignment()->getWrapText());
$cellValue = $firstSheet->getCell('A2')->getValue();
self::assertStringContainsString("\n", $cellValue);
$cellStyle = $firstSheet->getStyle('A3');
self::assertTrue($cellStyle->getAlignment()->getWrapText());
$cellValue = $firstSheet->getCell('A3')->getValue();
self::assertStringContainsString("\n", $cellValue);
$spreadsheet->disconnectWorksheets();
}
public function testRowspanInRendering(): void
{
$filename = 'tests/data/Reader/HTML/rowspan.html';
$reader = new Html();
$spreadsheet = $reader->load($filename);
$actual = $spreadsheet->getActiveSheet()->getMergeCells();
self::assertSame(['A2:C2' => 'A2:C2'], $actual);
$spreadsheet->disconnectWorksheets();
}
public function testTextIndentUseRowspan(): void
{
$html = '<table>
<tr>
<td>1</td>
<td rowspan="2" style="vertical-align: center;">Center Align</td>
<td>Row</td>
</tr>
<tr>
<td>2</td>
<td style="text-indent:9px">Text Indent</td>
</tr>
</table>';
$spreadsheet = HtmlHelper::loadHtmlStringIntoSpreadsheet($html);
$firstSheet = $spreadsheet->getSheet(0);
$style = $firstSheet->getCell('C2')->getStyle();
self::assertEquals(1, $style->getAlignment()->getIndent());
$spreadsheet->disconnectWorksheets();
}
public function testBorderWithRowspanAndColspan(): void
{
$html = '<table>
<tr>
<td style="border: 1px solid black;">NOT SPANNED</td>
<td rowspan="2" colspan="2" style="border: 1px solid black;">SPANNED</td>
</tr>
<tr>
<td style="border: 1px solid black;">NOT SPANNED</td>
</tr>
</table>';
$reader = new Html();
$spreadsheet = $reader->loadFromString($html);
$firstSheet = $spreadsheet->getSheet(0);
$style = $firstSheet->getStyle('B1:C2');
$borders = $style->getBorders();
$totalBorders = [
$borders->getTop(),
$borders->getLeft(),
$borders->getBottom(),
$borders->getRight(),
];
foreach ($totalBorders as $border) {
self::assertEquals(Border::BORDER_THIN, $border->getBorderStyle());
}
$spreadsheet->disconnectWorksheets();
}
public function testBorderWithColspan(): void
{
$html = '<table>
<tr>
<td style="border: 1px solid black;">NOT SPANNED</td>
<td colspan="2" style="border: 1px solid black;">SPANNED</td>
</tr>
<tr>
<td style="border: 1px solid black;">NOT SPANNED</td>
</tr>
</table>';
$reader = new Html();
$spreadsheet = $reader->loadFromString($html);
$firstSheet = $spreadsheet->getSheet(0);
$style = $firstSheet->getStyle('B1:B2');
$borders = $style->getBorders();
$totalBorders = [
$borders->getTop(),
$borders->getLeft(),
$borders->getBottom(),
$borders->getRight(),
];
foreach ($totalBorders as $border) {
self::assertEquals(Border::BORDER_THIN, $border->getBorderStyle());
}
$spreadsheet->disconnectWorksheets();
}
public function testDataType(): void
{
$html = '<table>
<tr>
<td data-type="b">1</td>
<td data-type="s">12345678987654</td>
<!-- in some cases, you may want to treat the string with beginning equal sign as a string rather than a formula -->
<td data-type="s">=B1</td>
<td data-type="d">2022-02-21 10:20:30</td>
<td data-type="null">null</td>
<td data-type="b">0</td>
<td data-type="invalid-datatype">text with invalid datatype</td>
</tr>
</table>';
$reader = new Html();
$spreadsheet = $reader->loadFromString($html);
$firstSheet = $spreadsheet->getSheet(0);
// check boolean data type and true
self::assertEquals(DataType::TYPE_BOOL, $firstSheet->getCell('A1')->getDataType());
self::assertIsBool($firstSheet->getCell('A1')->getValue());
self::assertTrue($firstSheet->getCell('A1')->getValue());
// check string data type
self::assertEquals(DataType::TYPE_STRING, $firstSheet->getCell('B1')->getDataType());
self::assertIsString($firstSheet->getCell('B1')->getValue());
// check string with beginning equal sign (=B1) and string datatype,is not formula
self::assertEquals(DataType::TYPE_STRING, $firstSheet->getCell('C1')->getDataType());
self::assertEquals('=B1', $firstSheet->getCell('C1')->getValue());
self::assertTrue($firstSheet->getCell('C1')->getStyle()->getQuotePrefix());
//check iso date
self::assertEqualsWithDelta($firstSheet->getCell('D1')->getValue(), 44613.43090277778, 1.0e-12);
//null
self::assertEquals($firstSheet->getCell('E1')->getValue(), null);
// check boolean data type and true
self::assertEquals(DataType::TYPE_BOOL, $firstSheet->getCell('F1')->getDataType());
self::assertIsBool($firstSheet->getCell('F1')->getValue());
self::assertFalse($firstSheet->getCell('F1')->getValue());
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Html/HtmlCharsetTest.php | tests/PhpSpreadsheetTests/Reader/Html/HtmlCharsetTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Html;
use PhpOffice\PhpSpreadsheet\Reader\Exception as ReaderException;
use PhpOffice\PhpSpreadsheet\Reader\Html;
use PHPUnit\Framework\TestCase;
class HtmlCharsetTest extends TestCase
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerCharset')]
public function testCharset(string $filename, string $expectedResult): void
{
if ($expectedResult === 'exception') {
$this->expectException(ReaderException::class);
$this->expectExceptionMessage('Failed to load');
}
$directory = 'tests/data/Reader/HTML';
$reader = new Html();
$spreadsheet = $reader->load("$directory/$filename");
$sheet = $spreadsheet->getActiveSheet();
self::assertSame($expectedResult, $sheet->getCell('A1')->getValue());
$spreadsheet->disconnectWorksheets();
}
public static function providerCharset(): array
{
return [
['charset.ISO-8859-1.html', 'À1'],
['charset.ISO-8859-1.html4.html', 'À1'],
['charset.ISO-8859-2.html', 'Ŕ1'],
['charset.nocharset.html', 'À1'],
['charset.UTF-8.html', 'À1'],
['charset.UTF-8.bom.html', 'À1'],
['charset.UTF-16.bebom.html', 'À1'],
['charset.UTF-16.lebom.html', 'À1'],
['charset.gb18030.html', '电视机'],
['charset.unknown.html', 'exception'],
['xhtml4.entity.xhtml', 'exception'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Html/Issue2942Test.php | tests/PhpSpreadsheetTests/Reader/Html/Issue2942Test.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Html;
use PhpOffice\PhpSpreadsheet\Reader\Exception as ReaderException;
use PhpOffice\PhpSpreadsheet\Reader\Html;
use PHPUnit\Framework\TestCase;
class Issue2942Test extends TestCase
{
public function testLoadFromString(): void
{
$content = '<table><tbody><tr><td>éàâèî</td></tr></tbody></table>';
$reader = new Html();
$spreadsheet = $reader->loadFromString($content);
$sheet = $spreadsheet->getActiveSheet();
self::assertSame('éàâèî', $sheet->getCell('A1')->getValue());
$spreadsheet->disconnectWorksheets();
}
public function testLoadFromFile(): void
{
$file = 'tests/data/Reader/HTML/utf8chars.html';
$reader = new Html();
$spreadsheet = $reader->loadSpreadsheetFromFile($file);
$sheet = $spreadsheet->getActiveSheet();
self::assertSame('Test Utf-8 characters voilà', $sheet->getTitle());
self::assertSame('éàâèî', $sheet->getCell('A1')->getValue());
self::assertSame('αβγδε', $sheet->getCell('B1')->getValue());
self::assertSame('𐐁𐐂𐐃 & だけち', $sheet->getCell('A2')->getValue());
self::assertSame('אבגדה', $sheet->getCell('B2')->getValue());
self::assertSame('𪔀𪔁𪔂', $sheet->getCell('C2')->getValue());
self::assertSame('᠐᠑᠒', $sheet->getCell('A3')->getValue());
self::assertSame('അആ', $sheet->getCell('B3')->getValue());
self::assertSame('กขฃ', $sheet->getCell('C3')->getValue());
self::assertSame('✀✐✠', $sheet->getCell('D3')->getValue());
$spreadsheet->disconnectWorksheets();
}
public function testLoadFromStringExtendFailure(): void
{
$this->expectException(ReaderException::class);
$this->expectExceptionMessage('Failed to load content ');
$content = '<table><tbody><tr><td>éàâèî</td></tr></tbody></table>';
$reader = new HtmlExtend();
$reader->loadFromString($content);
}
public function testInfo(): void
{
$file = 'tests/data/Reader/HTML/utf8chars.charset.html';
$reader = new Html();
$info = $reader->listWorksheetInfo($file);
self::assertCount(1, $info);
$info0 = $info[0];
self::assertSame('Test Utf-8 characters voilà', $info0['worksheetName']);
self::assertSame('D', $info0['lastColumnLetter']);
self::assertSame(3, $info0['lastColumnIndex']);
self::assertSame(7, $info0['totalRows']);
self::assertSame(4, $info0['totalColumns']);
$names = $reader->listWorksheetNames($file);
self::assertCount(1, $names);
self::assertSame('Test Utf-8 characters voilà', $names[0]);
// Following ignored, just make sure it's executable.
$reader->setLoadSheetsOnly([$names[0]]);
$spreadsheet = $reader->load($file);
$sheet = $spreadsheet->getActiveSheet();
self::assertSame('✀✐✠', $sheet->getCell('D3')->getValue());
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Html/HtmlExtend.php | tests/PhpSpreadsheetTests/Reader/Html/HtmlExtend.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Html;
use PhpOffice\PhpSpreadsheet\Reader\Exception as ReaderException;
class HtmlExtend extends \PhpOffice\PhpSpreadsheet\Reader\Html
{
protected static string $deliberate = 'deliberate';
protected static function replaceNonAsciiIfNeeded(string $convert): ?string
{
if (self::$deliberate !== '') {
throw new ReaderException(self::$deliberate);
}
return parent::replaceNonAsciiIfNeeded($convert);
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Html/OpacityTest.php | tests/PhpSpreadsheetTests/Reader/Html/OpacityTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Html;
use PhpOffice\PhpSpreadsheet\Reader\Html;
use PHPUnit\Framework\TestCase;
class OpacityTest extends TestCase
{
public function testOpacity(): void
{
$filename = 'tests/data/Reader/HTML/html.opacity.3.html';
$reader = new Html();
$spreadsheet = $reader->load($filename);
$sheet = $spreadsheet->getActiveSheet();
$drawings = $sheet->getDrawingCollection();
self::assertCount(1, $drawings);
self::assertNotNull($drawings[0]);
self::assertSame(60000, $drawings[0]->getOpacity());
self::assertSame(192, $drawings[0]->getHeight());
self::assertSame(192, $drawings[0]->getWidth());
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Html/HtmlTagsTest.php | tests/PhpSpreadsheetTests/Reader/Html/HtmlTagsTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Html;
use PhpOffice\PhpSpreadsheet\Reader\Html;
use PhpOffice\PhpSpreadsheet\Style\Border;
use PHPUnit\Framework\TestCase;
class HtmlTagsTest extends TestCase
{
public function testTags(): void
{
$reader = new Html();
$html1 = <<<EOF
<table><tbody>
<tr><td>1</td><td>2</td><td>3</td></tr>
<tr><td><a href='www.google.com'>hyperlink</a></td><td>5<hr></td><td>6</td></tr>
<tr><td>7</td><td>8</td><td>9</td></tr>
<tr><td>10</td><td>11</td><td>12</td></tr>
</tbody></table>
<hr>
<table><tbody>
<tr><td>1</td><td><i>2</i></td><td>3</td></tr>
<tr height='20'><td>4</td><td>5</td><td>6</td></tr>
<tr><td>7</td><td>8</td><td>9</td></tr>
<tr><td><ul><li>A</li><li>B</li><li>C</li></ul></td><td>11</td><td>12</td></tr>
</tbody></table>
<ul><li>D</li><li>E</li><li>F</li></ul>
<br>
<table><tbody>
<tr><td>M</td>
<td>
<table><tbody>
<tr><td>N</td><td>O</td></tr>
<tr><td>P</td><td>Q</td></tr>
</tbody></table>
</td>
<td>R</td>
</tr>
<tr><td>S</td><td>T</td><td>U</td></tr>
</tbody></table>
EOF;
$robj = $reader->loadFromString($html1);
$sheet = $robj->getActiveSheet();
self::assertEquals('www.google.com', $sheet->getCell('A2')->getHyperlink()->getUrl());
self::assertEquals('hyperlink', $sheet->getCell('A2')->getValue());
self::assertEquals(-1, $sheet->getRowDimension(11)->getRowHeight());
self::assertEquals(20, $sheet->getRowDimension(12)->getRowHeight());
self::assertEquals(5, $sheet->getCell('B2')->getValue());
self::assertEquals(Border::BORDER_THIN, $sheet->getCell('B3')->getStyle()->getBorders()->getBottom()->getBorderStyle());
self::assertEquals(6, $sheet->getCell('C4')->getValue());
self::assertEquals(Border::BORDER_THIN, $sheet->getCell('A9')->getStyle()->getBorders()->getBottom()->getBorderStyle());
self::assertEquals(2, $sheet->getCell('B11')->getValue());
self::assertTrue($sheet->getCell('B11')->getStyle()->getFont()->getItalic());
// list within table
self::assertEquals("A\nB\nC", $sheet->getCell('A14')->getValue());
self::assertTrue($sheet->getCell('A14')->getStyle()->getAlignment()->getWrapText());
// list outside of table
self::assertEquals('D', $sheet->getCell('A17')->getValue());
self::assertEquals('E', $sheet->getCell('A18')->getValue());
self::assertEquals('F', $sheet->getCell('A19')->getValue());
// embedded table
self::assertEquals('M', $sheet->getCell('A21')->getValue());
self::assertEquals('N', $sheet->getCell('B20')->getValue());
self::assertEquals('O', $sheet->getCell('C20')->getValue());
self::assertEquals('P', $sheet->getCell('B21')->getValue());
self::assertEquals('Q', $sheet->getCell('C21')->getValue());
self::assertEquals('R', $sheet->getCell('C23')->getValue());
self::assertEquals('S', $sheet->getCell('A24')->getValue());
}
public static function testTagsRowColSpans(): void
{
$reader = new Html();
$html1 = <<<EOF
<table>
<tr>
<th>Month</th>
<th>Savings</th>
<th>Expenses</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
<td rowspan="2">$50</td>
</tr>
<tr>
<td>February</td>
<td>$80</td>
</tr>
<tr>
<td rowspan="2" colspan="2" bgcolor="#00FFFF">Away in March</td>
<td>$30</td>
</tr>
<tr>
<td>$40</td>
</tr>
</table>
EOF;
$robj = $reader->loadFromString($html1);
$sheet = $robj->getActiveSheet();
self::assertEquals(['C2:C3' => 'C2:C3', 'A4:B5' => 'A4:B5'], $sheet->getMergeCells());
self::assertEquals('Away in March', $sheet->getCell('A4')->getValue());
self::assertEquals('00FFFF', $sheet->getCell('A4')->getStyle()->getFill()->getEndColor()->getRGB());
}
public static function testDoublyEmbeddedTable(): void
{
$reader = new Html();
$html1 = <<<EOF
<table><tbody>
<tr><td>1</td><td>2</td><td>3</td></tr>
<tr><td>4</td><td>5</td><td>6</td></tr>
<tr><td>7</td><td>8</td><td>9</td></tr>
<tr><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td></tr>
<tr><td>M</td>
<td>
<table><tbody>
<tr><td>N</td>
<td>
<table><tbody>
<tr><td>10</td><td>11</td></tr>
<tr><td>12</td><td>13</td></tr>
</tbody></table>
</td>
<td>Y</td>
</tr>
<tr><td>P</td><td>Q</td><td>X</td></tr>
</tbody></table>
</td>
<td>R</td>
</tr>
<tr><td>S</td><td>T</td><td>U</td></tr>
</tbody></table>
EOF;
$robj = $reader->loadFromString($html1);
$sheet = $robj->getActiveSheet();
self::assertEquals('1', $sheet->getCell('A1')->getValue());
self::assertEquals('2', $sheet->getCell('B1')->getValue());
self::assertEquals('3', $sheet->getCell('C1')->getValue());
self::assertEquals('4', $sheet->getCell('A2')->getValue());
self::assertEquals('5', $sheet->getCell('B2')->getValue());
self::assertEquals('6', $sheet->getCell('C2')->getValue());
self::assertEquals('7', $sheet->getCell('A3')->getValue());
self::assertEquals('8', $sheet->getCell('B3')->getValue());
self::assertEquals('9', $sheet->getCell('C3')->getValue());
self::assertEquals('10', $sheet->getCell('C5')->getValue());
self::assertEquals('11', $sheet->getCell('D5')->getValue());
self::assertEquals('12', $sheet->getCell('C6')->getValue());
self::assertEquals('13', $sheet->getCell('D6')->getValue());
self::assertEquals('N', $sheet->getCell('B6')->getValue());
self::assertEquals('M', $sheet->getCell('A7')->getValue());
self::assertEquals('Y', $sheet->getCell('E7')->getValue());
self::assertEquals('P', $sheet->getCell('B8')->getValue());
self::assertEquals('Q', $sheet->getCell('C8')->getValue());
self::assertEquals('X', $sheet->getCell('D8')->getValue());
self::assertEquals('R', $sheet->getCell('C10')->getValue());
self::assertEquals('S', $sheet->getCell('A11')->getValue());
self::assertEquals('T', $sheet->getCell('B11')->getValue());
self::assertEquals('U', $sheet->getCell('C11')->getValue());
}
public static function testTagsOutsideTable(): void
{
$reader = new Html();
$html1 = <<<EOF
<h1>Here comes a list</h1>
<ol>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
</ol>
And here's another
<ul>
<li>Item A</li>
<li>Item B</li>
</ul>
<ol>
Content before list
<li>Item I</li>
<li>Item II</li>
<li>This <i>is</i> <span style='color: #ff0000;'>rich</span> text</li>
</ol>
EOF;
$robj = $reader->loadFromString($html1);
$sheet = $robj->getActiveSheet();
self::assertTrue($sheet->getCell('A1')->getStyle()->getFont()->getBold());
self::assertEquals('Here comes a list', $sheet->getCell('A1')->getValue());
self::assertEquals('Item 1', $sheet->getCell('A3')->getValue());
self::assertEquals('Item 2', $sheet->getCell('A4')->getValue());
self::assertEquals('Item 3', $sheet->getCell('A5')->getValue());
self::assertEquals('Item 4', $sheet->getCell('A6')->getValue());
self::assertEquals('And here\'s another', $sheet->getCell('A7')->getValue());
self::assertEquals('Item A', $sheet->getCell('A9')->getValue());
self::assertEquals('Item B', $sheet->getCell('A10')->getValue());
self::assertEquals('Content before list', $sheet->getCell('A11')->getValue());
self::assertEquals('Item I', $sheet->getCell('A12')->getValue());
self::assertEquals('Item II', $sheet->getCell('A13')->getValue());
// TODO Rich Text not yet supported
}
public static function testHyperlinksWithRowspan(): void
{
$reader = new Html();
$html1 = <<<EOF
<table>
<tr>
<td rowspan="3">Title</td>
<td><a href="https://google.com">Link 1</a></td>
</tr>
<tr>
<td><a href="https://google.com">Link 2</a></td>
</tr>
<tr>
<td><a href="https://google.com">Link 3</a></td>
</tr>
</table>
EOF;
$robj = $reader->loadFromString($html1);
$sheet = $robj->getActiveSheet();
self::assertEquals('https://google.com', $sheet->getCell('B1')->getHyperlink()->getUrl());
self::assertEquals('https://google.com', $sheet->getCell('B2')->getHyperlink()->getUrl());
self::assertEquals('https://google.com', $sheet->getCell('B3')->getHyperlink()->getUrl());
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Html/HtmlLibxmlTest.php | tests/PhpSpreadsheetTests/Reader/Html/HtmlLibxmlTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Html;
use PhpOffice\PhpSpreadsheet\Reader\Html;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase;
/**
* Dom loadHtml usually succeeds even with invalid Html,
* although it will generate warning messages.
* This member demonstrates a method less intrusive than
* set_error_handler to detect if there has been a problem.
*/
class HtmlLibxmlTest extends TestCase
{
private Spreadsheet $spreadsheet;
protected function tearDown(): void
{
$this->spreadsheet->disconnectWorksheets();
unset($this->spreadsheet);
}
public function testLoadInvalidString(): void
{
$libxml = libxml_use_internal_errors();
$html = '<table<>';
$reader = new Html();
$reader->setSuppressLoadWarnings(true);
$this->spreadsheet = $reader->loadFromString($html);
self::assertNotEmpty($reader->getLibxmlMessages());
self::assertSame($libxml, libxml_use_internal_errors());
}
public function testLoadValidString(): void
{
$libxml = libxml_use_internal_errors();
$html = '<table>';
$reader = new Html();
$reader->setSuppressLoadWarnings(true);
$this->spreadsheet = $reader->loadFromString($html);
self::assertEmpty($reader->getLibxmlMessages());
self::assertSame($libxml, libxml_use_internal_errors());
}
public function testLoadValidStringNoSuppress(): void
{
$libxml = libxml_use_internal_errors();
$html = '<table>';
$reader = new Html();
$this->spreadsheet = $reader->loadFromString($html);
self::assertEmpty($reader->getLibxmlMessages());
self::assertSame($libxml, libxml_use_internal_errors());
}
public function testLoadValidFile(): void
{
$libxml = libxml_use_internal_errors();
$reader = new Html();
$reader->setSuppressLoadWarnings(true);
$file = 'tests/data/Reader/HTML/charset.ISO-8859-1.html4.html';
$this->spreadsheet = $reader->load($file);
self::assertEmpty($reader->getLibxmlMessages());
self::assertSame($libxml, libxml_use_internal_errors());
}
public function testLoadInvalidFile(): void
{
$libxml = libxml_use_internal_errors();
$reader = new Html();
$reader->setSuppressLoadWarnings(true);
$file = 'tests/data/Reader/HTML/badhtml.html';
$this->spreadsheet = $reader->load($file);
self::assertNotEmpty($reader->getLibxmlMessages());
self::assertSame($libxml, libxml_use_internal_errors());
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Html/HtmlImage2Test.php | tests/PhpSpreadsheetTests/Reader/Html/HtmlImage2Test.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Html;
use PhpOffice\PhpSpreadsheet\Exception as SpreadsheetException;
use PhpOffice\PhpSpreadsheet\Reader\Html as HtmlReader;
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class HtmlImage2Test extends TestCase
{
public function testDefault(): void
{
$reader = new HtmlReader();
self::assertFalse($reader->getAllowExternalImages());
}
public function testCanInsertImageGoodProtocolAllowed(): void
{
if (getenv('SKIP_URL_IMAGE_TEST') === '1') {
self::markTestSkipped('Skipped due to setting of environment variable');
}
$imagePath = 'https://phpspreadsheet.readthedocs.io/en/stable/topics/images/01-03-filter-icon-1.png';
$html = '<table>
<tr>
<td><img src="' . $imagePath . '" alt="test image voilà"></td>
</tr>
</table>';
$spreadsheet = HtmlHelper::loadHtmlStringIntoSpreadsheet($html, true);
$firstSheet = $spreadsheet->getSheet(0);
/** @var Drawing $drawing */
$drawing = $firstSheet->getDrawingCollection()[0];
self::assertEquals($imagePath, $drawing->getPath());
self::assertEquals('A1', $drawing->getCoordinates());
$spreadsheet->disconnectWorksheets();
}
public function testCanInsertImageGoodProtocolNotAllowed(): void
{
$imagePath = 'https://phpspreadsheet.readthedocs.io/en/stable/topics/images/01-03-filter-icon-1.png';
$html = '<table>
<tr>
<td><img src="' . $imagePath . '" alt="test image voilà"></td>
</tr>
</table>';
$spreadsheet = HtmlHelper::loadHtmlStringIntoSpreadsheet($html, false);
$firstSheet = $spreadsheet->getSheet(0);
self::assertCount(0, $firstSheet->getDrawingCollection());
$spreadsheet->disconnectWorksheets();
}
public function testCantInsertImageNotFoundAllowed(): void
{
if (getenv('SKIP_URL_IMAGE_TEST') === '1') {
self::markTestSkipped('Skipped due to setting of environment variable');
}
$imagePath = 'https://phpspreadsheet.readthedocs.io/en/latest/topics/images/xxx01-03-filter-icon-1.png';
$html = '<table>
<tr>
<td><img src="' . $imagePath . '" alt="test image voilà"></td>
</tr>
</table>';
$spreadsheet = HtmlHelper::loadHtmlStringIntoSpreadsheet($html, true);
$firstSheet = $spreadsheet->getSheet(0);
$drawingCollection = $firstSheet->getDrawingCollection();
self::assertCount(0, $drawingCollection);
$spreadsheet->disconnectWorksheets();
}
public function testCantInsertImageNotFoundNotAllowed(): void
{
$imagePath = 'https://phpspreadsheet.readthedocs.io/en/latest/topics/images/xxx01-03-filter-icon-1.png';
$html = '<table>
<tr>
<td><img src="' . $imagePath . '" alt="test image voilà"></td>
</tr>
</table>';
$spreadsheet = HtmlHelper::loadHtmlStringIntoSpreadsheet($html, false);
$firstSheet = $spreadsheet->getSheet(0);
$drawingCollection = $firstSheet->getDrawingCollection();
self::assertCount(0, $drawingCollection);
$spreadsheet->disconnectWorksheets();
}
#[DataProvider('providerBadProtocol')]
public function testCannotInsertImageBadProtocol(string $imagePath): void
{
$this->expectException(SpreadsheetException::class);
$this->expectExceptionMessage('Invalid protocol for linked drawing');
$html = '<table>
<tr>
<td><img src="' . $imagePath . '" alt="test image voilà"></td>
</tr>
</table>';
HtmlHelper::loadHtmlStringIntoSpreadsheet($html);
}
public static function providerBadProtocol(): array
{
return [
'unknown protocol' => ['httpx://example.com/image.png'],
'embedded whitespace' => ['ht tp://example.com/image.png'],
'control character' => ["\x14http://example.com/image.png"],
'mailto' => ['mailto:xyz@example.com'],
'mailto whitespace' => ['mail to:xyz@example.com'],
'phar' => ['phar://example.com/image.phar'],
'phar control' => ["\x14phar://example.com/image.phar"],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Html/BinderTest.php | tests/PhpSpreadsheetTests/Reader/Html/BinderTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Html;
use PhpOffice\PhpSpreadsheet\Cell\DataType;
use PhpOffice\PhpSpreadsheet\Cell\StringValueBinder;
use PhpOffice\PhpSpreadsheet\Reader\Html;
use PHPUnit\Framework\TestCase;
class BinderTest extends TestCase
{
public function testLoadFromString(): void
{
$data = <<<EOF
<table>
<tbody>
<tr><td>1</td><td>2</td><td>3</td></tr>
<tr><td>4</td><td>5</td><td>6</td></tr>
</tbody>
</table>
EOF;
$reader1 = new Html();
$spreadsheet1 = $reader1->loadFromString($data);
$sheet1 = $spreadsheet1->getActiveSheet();
$sheet1->getCell('A3')->setValueExplicit(7, DataType::TYPE_STRING);
$sheet1->getCell('B3')->setValueExplicit(8, DataType::TYPE_NUMERIC);
$sheet1->setCellValue('C3', 9);
$sheet1->fromArray([10, 11, 12], null, 'A4');
$expected1 = [
[1, 2, 3],
[4, 5, 6],
['7', 8, 9],
[10, 11, 12],
];
self::AssertSame($expected1, $sheet1->toArray(null, false, false));
$reader2 = new Html();
$reader2->setValueBinder(new StringValueBinder());
$spreadsheet2 = $reader2->loadFromString($data);
$sheet2 = $spreadsheet2->getActiveSheet();
$sheet2->getCell('A3')->setValueExplicit(7, DataType::TYPE_STRING);
$sheet2->getCell('B3')->setValueExplicit(8, DataType::TYPE_NUMERIC);
$sheet2->setCellValue('C3', 9);
$sheet2->fromArray([10, 11, 12], null, 'A4');
$expected2 = [
['1', '2', '3'],
['4', '5', '6'],
['7', 8, '9'],
['10', '11', '12'],
];
self::AssertSame($expected2, $sheet2->toArray(null, false, false));
$spreadsheet1->disconnectWorksheets();
$spreadsheet2->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Html/HtmlImageTest.php | tests/PhpSpreadsheetTests/Reader/Html/HtmlImageTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Html;
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
use PHPUnit\Framework\TestCase;
class HtmlImageTest extends TestCase
{
public function testCanInsertImage(): void
{
$imagePath = realpath(__DIR__ . '/../../../data/Reader/HTML/image.jpg');
$html = '<table>
<tr>
<td><img src="' . $imagePath . '" alt="test image voilà"></td>
</tr>
</table>';
$spreadsheet = HtmlHelper::loadHtmlStringIntoSpreadsheet($html);
$firstSheet = $spreadsheet->getSheet(0);
/** @var Drawing $drawing */
$drawing = $firstSheet->getDrawingCollection()[0];
self::assertEquals($imagePath, $drawing->getPath());
self::assertEquals('A1', $drawing->getCoordinates());
self::assertEquals('test image voilà', $drawing->getName());
self::assertEquals('100', $drawing->getWidth());
self::assertEquals('100', $drawing->getHeight());
}
public function testCanInsertImageWidth(): void
{
$imagePath = realpath(__DIR__ . '/../../../data/Reader/HTML/image.jpg');
$html = '<table>
<tr>
<td><img src="' . $imagePath . '" alt="test image" width="50"></td>
</tr>
</table>';
$spreadsheet = HtmlHelper::loadHtmlStringIntoSpreadsheet($html);
$firstSheet = $spreadsheet->getSheet(0);
/** @var Drawing $drawing */
$drawing = $firstSheet->getDrawingCollection()[0];
self::assertEquals('50', $drawing->getWidth());
self::assertEquals('50', $drawing->getHeight());
}
public function testCanInsertImageHeight(): void
{
$imagePath = realpath(__DIR__ . '/../../../data/Reader/HTML/image.jpg');
$html = '<table>
<tr>
<td><img src="' . $imagePath . '" height="75"></td>
</tr>
</table>';
$spreadsheet = HtmlHelper::loadHtmlStringIntoSpreadsheet($html);
$firstSheet = $spreadsheet->getSheet(0);
/** @var Drawing $drawing */
$drawing = $firstSheet->getDrawingCollection()[0];
self::assertEquals('', $drawing->getName());
self::assertEquals('75', $drawing->getWidth());
self::assertEquals('75', $drawing->getHeight());
}
public function testImageWithourSrc(): void
{
$html = '<table>
<tr>
<td><img></td>
</tr>
</table>';
$spreadsheet = HtmlHelper::loadHtmlStringIntoSpreadsheet($html);
$firstSheet = $spreadsheet->getSheet(0);
self::assertCount(0, $firstSheet->getDrawingCollection());
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Html/HtmlPhpunit10Test.php | tests/PhpSpreadsheetTests/Reader/Html/HtmlPhpunit10Test.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Html;
use PhpOffice\PhpSpreadsheet\Reader\Html;
use PHPUnit\Framework\TestCase;
/**
* There were problems running this test in HtmlTest with PhpUnit 10.
* This replacement seem to work.
*/
class HtmlPhpunit10Test extends TestCase
{
private static string $errorString;
protected function setUp(): void
{
self::$errorString = '';
set_error_handler([self::class, 'errorHandler']);
}
protected function tearDown(): void
{
restore_error_handler();
}
public static function errorHandler(int $errno, string $errstr): bool
{
if ($errno === E_WARNING) {
self::$errorString = $errstr;
return true; // stop error handling
}
return false; // continue error handling
}
public function testBadHtml(): void
{
$filename = 'tests/data/Reader/HTML/badhtml.html';
$reader = new Html();
self::assertTrue($reader->canRead($filename));
$reader->load($filename);
self::assertStringContainsString('DOMDocument::loadHTML', self::$errorString);
}
public function testLoadInvalidString(): void
{
$html = '<table<>';
(new Html())->loadFromString($html);
self::assertStringContainsString('DOMDocument::loadHTML', self::$errorString);
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Html/HtmlHelper.php | tests/PhpSpreadsheetTests/Reader/Html/HtmlHelper.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Html;
use PhpOffice\PhpSpreadsheet\Reader\Html;
use PhpOffice\PhpSpreadsheet\Shared\File;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
class HtmlHelper
{
public static function createHtml(string $html): string
{
$filename = File::temporaryFilename();
file_put_contents($filename, $html);
return $filename;
}
public static function loadHtmlIntoSpreadsheet(string $filename, bool $unlink = false, ?bool $allowExternalImages = null): Spreadsheet
{
$html = new Html();
if ($allowExternalImages !== null) {
$html->setAllowExternalImages($allowExternalImages);
}
$spreadsheet = $html->load($filename);
if ($unlink) {
unlink($filename);
}
return $spreadsheet;
}
public static function loadHtmlStringIntoSpreadsheet(string $content, ?bool $allowExternalImages = null): Spreadsheet
{
$html = new Html();
if ($allowExternalImages !== null) {
$html->setAllowExternalImages($allowExternalImages);
}
$spreadsheet = $html->loadFromString($content);
return $spreadsheet;
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Html/HtmlLoadStringTest.php | tests/PhpSpreadsheetTests/Reader/Html/HtmlLoadStringTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Html;
use PhpOffice\PhpSpreadsheet\Reader\Html;
use PHPUnit\Framework\TestCase;
class HtmlLoadStringTest extends TestCase
{
public function testCanLoadFromString(): void
{
$html = '<table>
<tr>
<td>Hello World</td>
</tr>
<tr>
<td>Hello<br />World</td>
</tr>
<tr>
<td>Hello<br>World</td>
</tr>
</table>';
$spreadsheet = (new Html())->loadFromString($html);
$firstSheet = $spreadsheet->getSheet(0);
$cellStyle = $firstSheet->getStyle('A1');
self::assertFalse($cellStyle->getAlignment()->getWrapText());
$cellStyle = $firstSheet->getStyle('A2');
self::assertTrue($cellStyle->getAlignment()->getWrapText());
$cellValue = $firstSheet->getCell('A2')->getValue();
self::assertStringContainsString("\n", $cellValue);
$cellStyle = $firstSheet->getStyle('A3');
self::assertTrue($cellStyle->getAlignment()->getWrapText());
$cellValue = $firstSheet->getCell('A3')->getValue();
self::assertStringContainsString("\n", $cellValue);
}
// testLoadInvalidString moved to HtmlPhpUnit10Test
public function testCanLoadFromStringIntoExistingSpreadsheet(): void
{
$html = '<table>
<tr>
<td>Hello World</td>
</tr>
<tr>
<td>Hello<br />World</td>
</tr>
<tr>
<td>Hello<br>World</td>
</tr>
</table>';
$reader = new Html();
$spreadsheet = $reader->loadFromString($html);
$firstSheet = $spreadsheet->getSheet(0);
$cellStyle = $firstSheet->getStyle('A1');
self::assertFalse($cellStyle->getAlignment()->getWrapText());
$cellStyle = $firstSheet->getStyle('A2');
self::assertTrue($cellStyle->getAlignment()->getWrapText());
$cellValue = $firstSheet->getCell('A2')->getValue();
self::assertStringContainsString("\n", $cellValue);
$cellStyle = $firstSheet->getStyle('A3');
self::assertTrue($cellStyle->getAlignment()->getWrapText());
$cellValue = $firstSheet->getCell('A3')->getValue();
self::assertStringContainsString("\n", $cellValue);
$reader->setSheetIndex(1);
$html = '<table>
<tr>
<td>Goodbye World</td>
</tr>
</table>';
self::assertEquals(1, $spreadsheet->getSheetCount());
$spreadsheet = $reader->loadFromString($html, $spreadsheet);
self::assertEquals(2, $spreadsheet->getSheetCount());
}
public function testCanLoadDuplicateTitle(): void
{
$html = <<<'EOF'
<html>
<head>
<title>Sheet</title>
</head>
<body>
<table><tr><td>1</td></tr></table>
</body>
</html>
EOF;
$reader = new Html();
$spreadsheet = $reader->loadFromString($html);
$reader->setSheetIndex(1);
$reader->loadFromString($html, $spreadsheet);
$reader->setSheetIndex(2);
$reader->loadFromString($html, $spreadsheet);
$sheet = $spreadsheet->getSheet(0);
self::assertEquals(1, $sheet->getCell('A1')->getValue());
self::assertEquals('Sheet', $sheet->getTitle());
$sheet = $spreadsheet->getSheet(1);
self::assertEquals(1, $sheet->getCell('A1')->getValue());
self::assertEquals('Sheet 1', $sheet->getTitle());
$sheet = $spreadsheet->getSheet(2);
self::assertEquals(1, $sheet->getCell('A1')->getValue());
self::assertEquals('Sheet 2', $sheet->getTitle());
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Html/Issue1107Test.php | tests/PhpSpreadsheetTests/Reader/Html/Issue1107Test.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Html;
use PhpOffice\PhpSpreadsheet\Reader\Html as HtmlReader;
use PhpOffice\PhpSpreadsheet\Shared\File;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Html as HtmlWriter;
use PHPUnit\Framework\TestCase;
class Issue1107Test extends TestCase
{
private string $outfile = '';
protected function tearDown(): void
{
if ($this->outfile !== '') {
unlink($this->outfile);
$this->outfile = '';
}
}
public function testIssue1107(): void
{
// failure due to cached file size
$outstr = str_repeat('a', 1023) . "\n";
$allout = str_repeat($outstr, 10);
$this->outfile = $outfile = File::temporaryFilename();
file_put_contents($outfile, $allout);
self::assertSame(10240, filesize($outfile));
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->getCell('A1')->setValue(1);
$writer = new HtmlWriter($spreadsheet);
$writer->save($outfile);
$spreadsheet->disconnectWorksheets();
$reader = new HtmlReader();
$spreadsheet2 = $reader->load($outfile);
$sheet2 = $spreadsheet2->getActiveSheet();
self::assertSame(1, $sheet2->getCell('A1')->getValue());
$spreadsheet2->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Ods/ArrayFormulaTest.php | tests/PhpSpreadsheetTests/Reader/Ods/ArrayFormulaTest.php | <?php
namespace PhpOffice\PhpSpreadsheetTests\Reader\Ods;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Cell\DataType;
use PhpOffice\PhpSpreadsheet\Reader\Ods;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class ArrayFormulaTest extends TestCase
{
/** @param float|mixed[] $expectedValue */
#[DataProvider('arrayFormulaReaderProvider')]
public function testArrayFormulaReader(
string $cellAddress,
string $expectedRange,
string $expectedFormula,
array|float $expectedValue
): void {
$filename = 'tests/data/Reader/Ods/ArrayFormulaTest.ods';
$reader = new Ods();
$spreadsheet = $reader->load($filename);
$worksheet = $spreadsheet->getActiveSheet();
$cell = $worksheet->getCell($cellAddress);
self::assertSame(DataType::TYPE_FORMULA, $cell->getDataType());
self::assertSame(['t' => 'array', 'ref' => $expectedRange], $cell->getFormulaAttributes());
self::assertSame($expectedFormula, strtoupper($cell->getValueString()));
Calculation::getInstance($spreadsheet)
->setInstanceArrayReturnType(
Calculation::RETURN_ARRAY_AS_ARRAY
);
$worksheet->calculateArrays();
$cell = $worksheet->getCell($cellAddress);
self::assertSame($expectedValue, $cell->getCalculatedValue());
if (is_array($expectedValue)) {
if ($expectedRange === "$cellAddress:$cellAddress") {
self::assertSame([$expectedValue], $worksheet->rangeToArray($expectedRange, formatData: false, reduceArrays: true));
} else {
self::assertSame($expectedValue, $worksheet->rangeToArray($expectedRange, formatData: false, reduceArrays: true));
}
} else {
self::assertSame([[$expectedValue]], $worksheet->rangeToArray($expectedRange, formatData: false, reduceArrays: true));
}
$spreadsheet->disconnectWorksheets();
}
public static function arrayFormulaReaderProvider(): array
{
return [
[
'B2',
'B2:C3',
'={2,3}*{4;5}',
[[8, 12], [10, 15]],
],
[
'E1',
'E1:H1',
'=SIN({-1,0,1,2})',
[[-0.8414709848078965, 0.0, 0.8414709848078965, 0.9092974268256817]],
],
[
'E3',
'E3:E3',
'=MAX(SIN({-1,0,1,2}))',
[0.9092974268256817],
],
[
'D5',
'D5:E6',
'=A5:B5*A5:A6',
[[4, 6], [8, 12]],
],
[
'D8',
'D8:E9',
'=A8:B8*A8:A9',
[[9, 12], [15, 20]],
],
[
'D11',
'D11:E12',
'=A11:B11*A11:A12',
[[16, 20], [24, 30]],
],
[
'D14',
'D14:E15',
'=A14:B14*A14:A15',
[[25, 30], [35, 42]],
],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Ods/MultiLineCommentTest.php | tests/PhpSpreadsheetTests/Reader/Ods/MultiLineCommentTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Ods;
use PhpOffice\PhpSpreadsheet\Reader\Ods;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional;
class MultiLineCommentTest extends AbstractFunctional
{
public function testMultipleParagraphs(): void
{
$filename = 'tests/data/Reader/Ods/issue.4081.ods';
$reader = new Ods();
$spreadsheet = $reader->load($filename);
$sheet = $spreadsheet->getActiveSheet();
self::assertSame("First line.\n\nSecond line.", $sheet->getComment('A1')->getText()->getPlainText());
$spreadsheet->disconnectWorksheets();
}
public function testOneParagraphMultipleSpans(): void
{
$spreadsheetOld = new Spreadsheet();
$sheetOld = $spreadsheetOld->getActiveSheet();
$sheetOld->getCell('A1')->setValue('Hello');
$text = $sheetOld->getComment('A1')->getText();
$text->createText('First');
$text->createText(' line.');
$text->createText("\n");
$text->createText("\n");
$text->createText("Second line.\nThird line.");
$spreadsheet = $this->writeAndReload($spreadsheetOld, 'Ods');
$spreadsheetOld->disconnectWorksheets();
$sheet = $spreadsheet->getActiveSheet();
self::assertSame("First line.\n\nSecond line.\nThird line.", $sheet->getComment('A1')->getText()->getPlainText());
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Ods/PageSetupTest.php | tests/PhpSpreadsheetTests/Reader/Ods/PageSetupTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Ods;
use PhpOffice\PhpSpreadsheet\Reader\Ods;
use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup;
use PHPUnit\Framework\TestCase;
class PageSetupTest extends TestCase
{
private const MARGIN_PRECISION = 0.00000001;
private const MARGIN_UNIT_CONVERSION = 2.54; // Inches to cm
public function testPageSetup(): void
{
$filename = 'tests/data/Reader/Ods/PageSetup.ods';
$reader = new Ods();
$spreadsheet = $reader->load($filename);
$assertions = $this->pageSetupAssertions();
$sheetCount = 0;
foreach ($spreadsheet->getAllSheets() as $worksheet) {
++$sheetCount;
if (!array_key_exists($worksheet->getTitle(), $assertions)) {
self::fail('Unexpected worksheet ' . $worksheet->getTitle());
}
$sheetAssertions = $assertions[$worksheet->getTitle()];
foreach ($sheetAssertions as $test => $expectedResult) {
$testMethodName = 'get' . ucfirst($test);
$actualResult = $worksheet->getPageSetup()->$testMethodName();
self::assertSame(
$expectedResult,
$actualResult,
"Failed assertion for Worksheet '{$worksheet->getTitle()}' {$test}"
);
}
}
self::assertCount($sheetCount, $assertions);
$spreadsheet->disconnectWorksheets();
}
public function testPageMargins(): void
{
$filename = 'tests/data/Reader/Ods/PageSetup.ods';
$reader = new Ods();
$spreadsheet = $reader->load($filename);
$assertions = $this->pageMarginAssertions();
$sheetCount = 0;
foreach ($spreadsheet->getAllSheets() as $worksheet) {
++$sheetCount;
if (!array_key_exists($worksheet->getTitle(), $assertions)) {
self::fail('Unexpected worksheet ' . $worksheet->getTitle());
}
$sheetAssertions = $assertions[$worksheet->getTitle()];
foreach ($sheetAssertions as $test => $expectedResult) {
$testMethodName = 'get' . ucfirst($test);
$actualResult = $worksheet->getPageMargins()->$testMethodName();
self::assertEqualsWithDelta(
$expectedResult,
$actualResult,
self::MARGIN_PRECISION,
"Failed assertion for Worksheet '{$worksheet->getTitle()}' {$test} margin"
);
}
}
self::assertCount($sheetCount, $assertions);
$spreadsheet->disconnectWorksheets();
}
/** @return array<string, array<string, mixed>> */
private function pageSetupAssertions(): array
{
return [
'Sheet1' => [
'orientation' => PageSetup::ORIENTATION_PORTRAIT,
'scale' => 75,
'horizontalCentered' => true,
'verticalCentered' => false,
'pageOrder' => PageSetup::PAGEORDER_DOWN_THEN_OVER,
],
'Sheet2' => [
'orientation' => PageSetup::ORIENTATION_LANDSCAPE,
'scale' => 100,
'horizontalCentered' => false,
'verticalCentered' => true,
'pageOrder' => PageSetup::PAGEORDER_OVER_THEN_DOWN,
],
'Sheet3' => [
'orientation' => PageSetup::ORIENTATION_PORTRAIT,
'scale' => 90,
'horizontalCentered' => true,
'verticalCentered' => true,
'pageOrder' => PageSetup::PAGEORDER_DOWN_THEN_OVER,
],
'Sheet4' => [
// Default Settings
'orientation' => PageSetup::ORIENTATION_DEFAULT,
'scale' => 100,
'horizontalCentered' => false,
'verticalCentered' => false,
'pageOrder' => PageSetup::PAGEORDER_DOWN_THEN_OVER,
],
];
}
/** @return array<string, array<string, float>> */
private function pageMarginAssertions(): array
{
return [
'Sheet1' => [
// Here the values are in cm
'top' => 0.8 / self::MARGIN_UNIT_CONVERSION,
'header' => 1.6 / self::MARGIN_UNIT_CONVERSION,
'left' => 1.3 / self::MARGIN_UNIT_CONVERSION,
'right' => 1.3 / self::MARGIN_UNIT_CONVERSION,
'bottom' => 0.8 / self::MARGIN_UNIT_CONVERSION,
'footer' => 1.1 / self::MARGIN_UNIT_CONVERSION,
],
'Sheet2' => [
// Here the values are in cm
'top' => 0.8 / self::MARGIN_UNIT_CONVERSION,
'header' => 1.1 / self::MARGIN_UNIT_CONVERSION,
'left' => 1.8 / self::MARGIN_UNIT_CONVERSION,
'right' => 1.8 / self::MARGIN_UNIT_CONVERSION,
'bottom' => 0.8 / self::MARGIN_UNIT_CONVERSION,
'footer' => 1.1 / self::MARGIN_UNIT_CONVERSION,
],
'Sheet3' => [
// Here the values are in cm
'top' => 1.3 / self::MARGIN_UNIT_CONVERSION,
'header' => 1.1 / self::MARGIN_UNIT_CONVERSION,
'left' => 1.8 / self::MARGIN_UNIT_CONVERSION,
'right' => 1.8 / self::MARGIN_UNIT_CONVERSION,
'bottom' => 1.3 / self::MARGIN_UNIT_CONVERSION,
'footer' => 1.1 / self::MARGIN_UNIT_CONVERSION,
],
'Sheet4' => [
// Default Settings (already in inches)
'top' => 0.3,
'header' => 0.45,
'left' => 0.7,
'right' => 0.7,
'bottom' => 0.3,
'footer' => 0.45,
],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Ods/Issue2810Test.php | tests/PhpSpreadsheetTests/Reader/Ods/Issue2810Test.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Ods;
use PhpOffice\PhpSpreadsheet\Reader\Ods;
use PHPUnit\Framework\TestCase;
class Issue2810Test extends TestCase
{
public function testIssue2810(): void
{
// Active sheet with title of '0' wasn't found
$filename = 'tests/data/Reader/Ods/issue.2810.ods';
$reader = new Ods();
$spreadsheet = $reader->load($filename);
$sheet = $spreadsheet->getActiveSheet();
self::assertSame('Active', $sheet->getCell('A1')->getValue());
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Ods/MergeRangeTest.php | tests/PhpSpreadsheetTests/Reader/Ods/MergeRangeTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Ods;
use PhpOffice\PhpSpreadsheet\Reader\Ods;
use PHPUnit\Framework\TestCase;
class MergeRangeTest extends TestCase
{
public function testAutoFilterRange(): void
{
$filename = 'tests/data/Reader/Ods/MergeRangeTest.ods';
$reader = new Ods();
$spreadsheet = $reader->load($filename);
$worksheet = $spreadsheet->getActiveSheet();
$mergeRanges = $worksheet->getMergeCells();
self::assertArrayHasKey('B2:C3', $mergeRanges);
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Ods/HyperlinkTest.php | tests/PhpSpreadsheetTests/Reader/Ods/HyperlinkTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Ods;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Ods;
use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional;
class HyperlinkTest extends AbstractFunctional
{
public function testSaveAndLoadHyperlinks(): void
{
$spreadsheetOld = new Spreadsheet();
$spreadsheetOld->getProperties()->setCompany('g</meta:user-defined>zorg');
$spreadsheetOld->getProperties()->setCategory('h</meta:user-defined>zorg');
$sheet = $spreadsheetOld->getActiveSheet();
$sheet->getCell('A1')->setValue('Hello World');
$sheet->getCell('A2')->setValue('http://example.org');
$sheet->getCell('A2')->getHyperlink()->setUrl('http://example.org/');
$sheet->getCell('A3')->setValue('pa<ge1');
$sheet->getCell('A3')->getHyperlink()->setUrl('http://example.org/page1.html');
$sheet2 = $spreadsheetOld->createSheet();
$sheet2->setTitle('TargetSheet');
$sheet2->setCellValue('B4', 'TargetCell');
$sheet2->setCellValue('B3', 'not target');
$sheet->getCell('A4')->setValue('go to Target');
$sheet->getCell('A4')->getHyperlink()->setUrl('sheet://TargetSheet!B4');
$spreadsheet = $this->writeAndReload($spreadsheetOld, 'Ods');
$spreadsheetOld->disconnectWorksheets();
$newSheet = $spreadsheet->getActiveSheet();
self::assertSame('g</meta:user-defined>zorg', $spreadsheet->getProperties()->getCompany());
self::assertSame('h</meta:user-defined>zorg', $spreadsheet->getProperties()->getCategory());
self::assertSame('http://example.org', $newSheet->getCell('A2')->getValue());
self::assertSame('http://example.org/', $newSheet->getCell('A2')->getHyperlink()->getUrl());
self::assertSame('pa<ge1', $newSheet->getCell('A3')->getValue());
self::assertSame('http://example.org/page1.html', $newSheet->getCell('A3')->getHyperlink()->getUrl());
self::assertSame('go to Target', $newSheet->getCell('A4')->getValue());
self::assertSame('sheet://TargetSheet!B4', $newSheet->getCell('A4')->getHyperlink()->getUrl());
// Verify that http links are unchanged,
// but internal sheet link has changed.
$writer = new Ods($spreadsheet);
$content = $writer->getWriterPartContent()->write();
self::assertStringContainsString('xlink:href="http://example.org/"', $content);
self::assertStringContainsString('xlink:href="http://example.org/page1.html"', $content);
self::assertStringContainsString('xlink:href="#TargetSheet!B4"', $content);
self::assertStringNotContainsString('sheet:', $content);
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Ods/FormulaTranslatorTest.php | tests/PhpSpreadsheetTests/Reader/Ods/FormulaTranslatorTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Ods;
use PhpOffice\PhpSpreadsheet\Reader\Ods\FormulaTranslator;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class FormulaTranslatorTest extends TestCase
{
#[DataProvider('addressesProvider')]
public function testAddresses(string $result, string $address): void
{
self::assertSame($result, FormulaTranslator::convertToExcelAddressValue($address));
}
public static function addressesProvider(): array
{
return [
'range period in sheet name' => ["'sheet1.bug'!a1:a5", "'sheet1.bug'.a1:'sheet1.bug'.a5"],
'range special chars and period in sheet name' => ["'#sheet1.x'!a1:a5", "'#sheet1.x'.a1:'#sheet1.x'.a5"],
'cell period in sheet name' => ["'sheet1.bug'!b9", "'sheet1.bug'.b9"],
'range unquoted sheet name' => ['sheet1!b9:c12', 'sheet1.b9:sheet1.c12'],
'range unquoted sheet name with $' => ['sheet1!$b9:c$12', 'sheet1.$b9:sheet1.c$12'],
'range quoted sheet name with $' => ["'sheet1'!\$b9:c\$12", '\'sheet1\'.$b9:\'sheet1\'.c$12'],
'cell unquoted sheet name' => ['sheet1!B$9', 'sheet1.B$9'],
'range no sheet name all dollars' => ['$B$9:$C$12', '$B$9:$C$12'],
'range no sheet name some dollars' => ['B$9:$C12', 'B$9:$C12'],
'range no sheet name no dollars' => ['B9:C12', 'B9:C12'],
];
}
#[DataProvider('formulaProvider')]
public function testFormulas(string $result, string $formula): void
{
self::assertSame($result, FormulaTranslator::convertToExcelFormulaValue($formula));
}
public static function formulaProvider(): array
{
return [
'ranges no sheet name' => [
'SUM(A5:A7,B$5:$B7)',
'SUM([.A5:.A7];[.B$5:.$B7])',
],
'ranges sheet name with period' => [
'SUM(\'test.bug\'!A5:A7,\'test.bug\'!B5:B7)',
'SUM([\'test.bug\'.A5:.A7];[\'test.bug\'.B5:.B7])',
],
'ranges unquoted sheet name' => [
'SUM(testbug!A5:A7,testbug!B5:B7)',
'SUM([testbug.A5:.A7];[testbug.B5:.B7])',
],
'ranges quoted sheet name without period' => [
'SUM(\'testbug\'!A5:A7,\'testbug\'!B5:B7)',
'SUM([\'testbug\'.A5:.A7];[\'testbug\'.B5:.B7])',
],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Ods/PageSetupBug1772Test.php | tests/PhpSpreadsheetTests/Reader/Ods/PageSetupBug1772Test.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Ods;
use PhpOffice\PhpSpreadsheet\Reader\Ods;
use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup;
use PHPUnit\Framework\TestCase;
class PageSetupBug1772Test extends TestCase
{
private const MARGIN_PRECISION = 0.00000001;
public function testPageSetup(): void
{
$filename = 'tests/data/Reader/Ods/bug1772.ods';
$reader = new Ods();
$spreadsheet = $reader->load($filename);
$assertions = $this->pageSetupAssertions();
$sheetCount = 0;
foreach ($spreadsheet->getAllSheets() as $worksheet) {
++$sheetCount;
if (!array_key_exists($worksheet->getTitle(), $assertions)) {
self::fail('Unexpected worksheet ' . $worksheet->getTitle());
}
$sheetAssertions = $assertions[$worksheet->getTitle()];
foreach ($sheetAssertions as $test => $expectedResult) {
$testMethodName = 'get' . ucfirst($test);
$actualResult = $worksheet->getPageSetup()->$testMethodName();
self::assertSame(
$expectedResult,
$actualResult,
"Failed assertion for Worksheet '{$worksheet->getTitle()}' {$test}"
);
}
}
self::assertCount($sheetCount, $assertions);
$spreadsheet->disconnectWorksheets();
}
public function testPageMargins(): void
{
$filename = 'tests/data/Reader/Ods/bug1772.ods';
$reader = new Ods();
$spreadsheet = $reader->load($filename);
$assertions = $this->pageMarginAssertions();
$sheetCount = 0;
foreach ($spreadsheet->getAllSheets() as $worksheet) {
++$sheetCount;
if (!array_key_exists($worksheet->getTitle(), $assertions)) {
self::fail('Unexpected worksheet ' . $worksheet->getTitle());
}
$sheetAssertions = $assertions[$worksheet->getTitle()];
foreach ($sheetAssertions as $test => $expectedResult) {
$testMethodName = 'get' . ucfirst($test);
$actualResult = $worksheet->getPageMargins()->$testMethodName();
self::assertEqualsWithDelta(
$expectedResult,
$actualResult,
self::MARGIN_PRECISION,
"Failed assertion for Worksheet '{$worksheet->getTitle()}' {$test} margin"
);
}
}
self::assertCount($sheetCount, $assertions);
$spreadsheet->disconnectWorksheets();
}
/** @return array<string, array<string, mixed>> */
private function pageSetupAssertions(): array
{
return [
'Employee update template' => [
'orientation' => PageSetup::ORIENTATION_DEFAULT,
'scale' => 100,
'horizontalCentered' => false,
'verticalCentered' => false,
'pageOrder' => PageSetup::PAGEORDER_DOWN_THEN_OVER,
],
];
}
/** @return array<string, array<string, float>> */
private function pageMarginAssertions(): array
{
return [
'Employee update template' => [
// Here the values are in cm
'top' => 0.0,
'header' => 0.2953,
'left' => 0.0,
'right' => 0.0,
'bottom' => 0.0,
'footer' => 0.2953,
],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Ods/ArrayTest.php | tests/PhpSpreadsheetTests/Reader/Ods/ArrayTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Ods;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional;
class ArrayTest extends AbstractFunctional
{
public function testSaveAndLoadHyperlinks(): void
{
$spreadsheetOld = new Spreadsheet();
Calculation::getInstance($spreadsheetOld)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY);
$sheet = $spreadsheetOld->getActiveSheet();
$sheet->getCell('A1')->setValue('a');
$sheet->getCell('A2')->setValue('b');
$sheet->getCell('A3')->setValue('c');
$sheet->getCell('C1')->setValue(1);
$sheet->getCell('C2')->setValue(2);
$sheet->getCell('C3')->setValue(3);
$sheet->getCell('B1')->setValue('=CONCATENATE(A1:A3,"-",C1:C3)');
$spreadsheet = $this->writeAndReload($spreadsheetOld, 'Ods');
$spreadsheetOld->disconnectWorksheets();
$newSheet = $spreadsheet->getActiveSheet();
self::assertSame(['t' => 'array', 'ref' => 'B1:B3'], $newSheet->getCell('B1')->getFormulaAttributes());
self::assertSame('a-1', $newSheet->getCell('B1')->getOldCalculatedValue());
self::assertSame('b-2', $newSheet->getCell('B2')->getValue());
self::assertSame('c-3', $newSheet->getCell('B3')->getValue());
self::assertSame('=CONCATENATE(A1:A3,"-",C1:C3)', $newSheet->getCell('B1')->getValue());
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Ods/DefinedNamesTest.php | tests/PhpSpreadsheetTests/Reader/Ods/DefinedNamesTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Ods;
use PhpOffice\PhpSpreadsheet\Reader\Ods;
use PHPUnit\Framework\TestCase;
class DefinedNamesTest extends TestCase
{
public function testDefinedNamesValue(): void
{
$filename = 'tests/data/Reader/Ods/DefinedNames.ods';
$reader = new Ods();
$spreadsheet = $reader->load($filename);
$spreadsheet->returnArrayAsValue();
$worksheet = $spreadsheet->getActiveSheet();
$firstDefinedNameValue = $worksheet->getCell('First')->getValue();
$secondDefinedNameValue = $worksheet->getCell('Second')->getValue();
$calculatedFormulaValue = $worksheet->getCell('B2')->getCalculatedValue();
self::assertSame(3, $firstDefinedNameValue);
self::assertSame(4, $secondDefinedNameValue);
self::assertSame(12, $calculatedFormulaValue);
$spreadsheet->disconnectWorksheets();
}
public function testDefinedNamesApostropheValue(): void
{
$filename = 'tests/data/Reader/Ods/DefinedNames.apostrophe.ods';
$reader = new Ods();
$spreadsheet = $reader->load($filename);
$spreadsheet->returnArrayAsValue();
$worksheet = $spreadsheet->getActiveSheet();
self::assertSame("apo'strophe", $worksheet->getTitle());
$firstDefinedNameValue = $worksheet->getCell('First')->getValue();
$secondDefinedNameValue = $worksheet->getCell('Second')->getValue();
$calculatedFormulaValue = $worksheet->getCell('B2')->getCalculatedValue();
self::assertSame(3, $firstDefinedNameValue);
self::assertSame(4, $secondDefinedNameValue);
self::assertSame(12, $calculatedFormulaValue);
$spreadsheet->disconnectWorksheets();
}
public function testDefinedNamesArray(): void
{
$filename = 'tests/data/Reader/Ods/DefinedNames.ods';
$reader = new Ods();
$spreadsheet = $reader->load($filename);
$spreadsheet->returnArrayAsArray();
$worksheet = $spreadsheet->getActiveSheet();
$firstDefinedNameValue = $worksheet->getCell('First')->getValue();
$secondDefinedNameValue = $worksheet->getCell('Second')->getValue();
$calculatedFormulaValue = $worksheet->getCell('B2')->getCalculatedValue();
self::assertSame(3, $firstDefinedNameValue);
self::assertSame(4, $secondDefinedNameValue);
self::assertSame([12], $calculatedFormulaValue);
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Ods/EmptyFileTest.php | tests/PhpSpreadsheetTests/Reader/Ods/EmptyFileTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Ods;
use PhpOffice\PhpSpreadsheet\Reader\Exception as ReaderException;
use PhpOffice\PhpSpreadsheet\Reader\Ods;
use PhpOffice\PhpSpreadsheet\Shared\File;
use PHPUnit\Framework\TestCase;
class EmptyFileTest extends TestCase
{
private string $tempfile = '';
protected function tearDown(): void
{
if ($this->tempfile !== '') {
unlink($this->tempfile);
$this->tempfile = '';
}
}
public function testEmptyFileLoad(): void
{
$this->expectException(ReaderException::class);
$this->expectExceptionMessage('Could not find zip member');
$this->tempfile = $temp = File::temporaryFileName();
file_put_contents($temp, '');
$reader = new Ods();
$reader->load($temp);
}
public function testEmptyFileNames(): void
{
$this->expectException(ReaderException::class);
$this->expectExceptionMessage('Could not find zip member');
$this->tempfile = $temp = File::temporaryFileName();
file_put_contents($temp, '');
$reader = new Ods();
$reader->listWorksheetNames($temp);
}
public function testEmptyInfo(): void
{
$this->expectException(ReaderException::class);
$this->expectExceptionMessage('Could not find zip member');
$this->tempfile = $temp = File::temporaryFileName();
file_put_contents($temp, '');
$reader = new Ods();
$reader->listWorksheetInfo($temp);
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Ods/Issue3721Test.php | tests/PhpSpreadsheetTests/Reader/Ods/Issue3721Test.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Ods;
use PhpOffice\PhpSpreadsheet\Reader\Ods;
use PHPUnit\Framework\TestCase;
class Issue3721Test extends TestCase
{
public function testIssue2810(): void
{
// Problems with getHighestDataColumn
$filename = 'tests/data/Reader/Ods/issue.3721.ods';
$reader = new Ods();
$spreadsheet = $reader->load($filename);
$sheet = $spreadsheet->getSheetByNameOrThrow('sheet with data');
$origHigh = $sheet->getHighestDataColumn();
self::assertSame('C', $origHigh);
$cells = [];
foreach ($sheet->getRowIterator() as $row) {
foreach ($row->getCellIterator(iterateOnlyExistingCells: true) as $cell) {
$cells[] = $cell->getCoordinate();
}
}
self::assertSame(['A1', 'B1', 'C1', 'A2', 'B2', 'C2'], $cells);
self::assertSame('C', $sheet->getHighestDataColumn());
self::assertSame('BL', $sheet->getHighestColumn());
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Ods/HiddenMergeCellsTest.php | tests/PhpSpreadsheetTests/Reader/Ods/HiddenMergeCellsTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Ods;
use PhpOffice\PhpSpreadsheet\Reader\Ods;
use PHPUnit\Framework\TestCase;
class HiddenMergeCellsTest extends TestCase
{
private const FILENAME = 'tests/data/Reader/Ods/HiddenMergeCellsTest.ods';
public function testHiddenMergeCells(): void
{
$reader = new Ods();
$spreadsheet = $reader->load(self::FILENAME);
$c2InMergeRange = $spreadsheet->getActiveSheet()->getCell('C2')->isInMergeRange();
self::assertTrue($c2InMergeRange);
$a2InMergeRange = $spreadsheet->getActiveSheet()->getCell('A2')->isInMergeRange();
self::assertTrue($a2InMergeRange);
$a2MergeRangeValue = $spreadsheet->getActiveSheet()->getCell('A2')->isMergeRangeValueCell();
self::assertTrue($a2MergeRangeValue);
$cellArray = $spreadsheet->getActiveSheet()->rangeToArray('A2:C2');
self::assertSame([['12', '4', '3']], $cellArray);
$cellArray = $spreadsheet->getActiveSheet()->rangeToArray('A2:C2', null, true, false);
self::assertSame([[12, 4, 3]], $cellArray);
$spreadsheet->disconnectWorksheets();
}
public function testUnmergeHiddenMergeCells(): void
{
$reader = new Ods();
$spreadsheet = $reader->load(self::FILENAME);
$spreadsheet->getActiveSheet()->unmergeCells('A2:C2');
$c2InMergeRange = $spreadsheet->getActiveSheet()->getCell('C2')->isInMergeRange();
self::assertFalse($c2InMergeRange);
$a2InMergeRange = $spreadsheet->getActiveSheet()->getCell('A2')->isInMergeRange();
self::assertFalse($a2InMergeRange);
$cellArray = $spreadsheet->getActiveSheet()->rangeToArray('A2:C2', null, false, false, false);
self::assertSame([[12, '=6-B1', '=A2/B2']], $cellArray);
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Ods/OdsInfoTest.php | tests/PhpSpreadsheetTests/Reader/Ods/OdsInfoTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Ods;
use PhpOffice\PhpSpreadsheet\Reader\Exception as ReaderException;
use PhpOffice\PhpSpreadsheet\Reader\Ods;
use PHPUnit\Framework\TestCase;
/**
* @TODO The class doesn't read the bold/italic/underline properties (rich text)
*/
class OdsInfoTest extends TestCase
{
public function testReadFileProperties(): void
{
$filename = 'tests/data/Reader/Ods/data.ods';
// Load into this instance
$reader = new Ods();
// Test "listWorksheetNames" method
self::assertSame([
'Sheet1',
'Second Sheet',
], $reader->listWorksheetNames($filename));
}
public function testNoMimeType(): void
{
$filename = 'tests/data/Reader/Ods/nomimetype.ods';
// Load into this instance
$reader = new Ods();
self::assertTrue($reader->canRead($filename));
}
public function testReadBadFileProperties(): void
{
$this->expectException(ReaderException::class);
// Load into this instance
$reader = new Ods();
// Test "listWorksheetNames" method
self::assertSame([
'Sheet1',
'Second Sheet',
], $reader->listWorksheetNames(__FILE__));
}
public function testReadFileInfo(): void
{
$filename = 'tests/data/Reader/Ods/data.ods';
$reader = new Ods();
$wsinfo = $reader->listWorkSheetInfo($filename);
self::assertSame([
[
'worksheetName' => 'Sheet1',
'lastColumnLetter' => 'C',
'lastColumnIndex' => 2,
'totalRows' => 12,
'totalColumns' => 3,
'sheetState' => 'visible',
],
[
'worksheetName' => 'Second Sheet',
'lastColumnLetter' => 'B',
'lastColumnIndex' => 1,
'totalRows' => 2,
'totalColumns' => 2,
'sheetState' => 'visible',
],
], $wsinfo);
}
public function testReadBadFileInfo(): void
{
$this->expectException(ReaderException::class);
$filename = __FILE__;
$reader = new Ods();
$wsinfo = $reader->listWorkSheetInfo($filename);
}
public function testReadFileInfoWithEmpties(): void
{
$filename = 'tests/data/Reader/Ods/RepeatedCells.ods';
$reader = new Ods();
$wsinfo = $reader->listWorkSheetInfo($filename);
self::assertSame([
[
'worksheetName' => 'Sheet1',
'lastColumnLetter' => 'K',
'lastColumnIndex' => 10,
'totalRows' => 1,
'totalColumns' => 11,
'sheetState' => 'visible',
],
], $wsinfo);
}
public function testOneMoreWorksheetInfo(): void
{
$filename = 'tests/data/Reader/Ods/issue.4528.ods';
$reader = new Ods();
$wsinfo = $reader->listWorkSheetInfo($filename);
self::assertSame([
[
'worksheetName' => 'Francais',
'lastColumnLetter' => 'AZ',
'lastColumnIndex' => 51,
'totalRows' => 811,
'totalColumns' => 52,
'sheetState' => 'visible',
],
], $wsinfo);
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Ods/RepeatEmptyCellsAndRowsTest.php | tests/PhpSpreadsheetTests/Reader/Ods/RepeatEmptyCellsAndRowsTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Ods;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional;
class RepeatEmptyCellsAndRowsTest extends AbstractFunctional
{
public function testSaveAndLoadHyperlinks(): void
{
$spreadsheetOld = new Spreadsheet();
$oldSheet = $spreadsheetOld->getActiveSheet();
$oldSheet->setCellValue('C1', 'xx');
$oldSheet->setCellValue('G1', 'aa');
$oldSheet->setCellValue('BB1', 'bb');
$oldSheet->setCellValue('A6', 'aaa');
$oldSheet->setCellValue('B7', 'bbb');
$oldSheet->getRowDimension(10)->setRowHeight(12);
$oldSheet->setCellValue('A12', 'this is A12');
$style = $oldSheet->getStyle('B14:D14');
$style->getFont()->setBold(true);
$oldSheet->getCell('E15')->setValue('X');
$oldSheet->mergeCells('E15:G16');
$oldSheet->getCell('J15')->setValue('j15');
$oldSheet->getCell('J16')->setValue('j16');
$oldSheet->getCell('A19')->setValue('lastrow');
$spreadsheet = $this->writeAndReload($spreadsheetOld, 'Ods');
$spreadsheetOld->disconnectWorksheets();
$sheet = $spreadsheet->getActiveSheet();
self::assertSame('xx', $sheet->getCell('C1')->getValue());
self::assertSame('aa', $sheet->getCell('G1')->getValue());
self::assertSame('bb', $sheet->getCell('BB1')->getValue());
self::assertSame('aaa', $sheet->getCell('A6')->getValue());
self::assertSame('bbb', $sheet->getCell('B7')->getValue());
self::assertSame('this is A12', $sheet->getCell('A12')->getValue());
// Read styles, including row height, not yet implemented for ODS
self::assertSame('j15', $sheet->getCell('J15')->getValue());
self::assertSame('j16', $sheet->getCell('J16')->getValue());
self::assertSame(['E15:G16' => 'E15:G16'], $sheet->getMergeCells());
self::assertSame('lastrow', $sheet->getCell('A19')->getValue());
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Ods/Issue804Test.php | tests/PhpSpreadsheetTests/Reader/Ods/Issue804Test.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Ods;
use PhpOffice\PhpSpreadsheet\Reader\Ods;
use PHPUnit\Framework\TestCase;
class Issue804Test extends TestCase
{
public function testPreliminaries(): void
{
$file = 'zip://';
$file .= 'tests/data/Reader/Ods/issue.804.ods';
$file .= '#content.xml';
$data = file_get_contents($file);
// confirm that file contains expected namespaced xml tag
if ($data === false) {
self::fail('Unable to read file');
} else {
self::assertStringContainsString('<table:table-row>
<table:table-cell office:value-type="string" table:number-rows-spanned="1" table:style-name="heading">
<text:p>Name</text:p>', $data);
}
}
public function testIssue2810(): void
{
// Whitespace between Xml nodes
$filename = 'tests/data/Reader/Ods/issue.804.ods';
$reader = new Ods();
$spreadsheet = $reader->load($filename);
$sheet = $spreadsheet->getActiveSheet();
self::assertSame('Straße', $sheet->getCell('G1')->getValue());
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Ods/CeilingFloorTest.php | tests/PhpSpreadsheetTests/Reader/Ods/CeilingFloorTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Ods;
use PhpOffice\PhpSpreadsheet\Reader\Ods as OdsReader;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional;
class CeilingFloorTest extends AbstractFunctional
{
private const INFILE = 'tests/data/Reader/Ods/issue.407.ods';
private const EXPECTED_ODS = [
'A1' => '=FLOOR(2.5,1)',
'A2' => '=FLOOR.MATH(2.5,1)',
'A3' => '=FLOOR.PRECISE(2.5,1)',
'A4' => '=FLOOR.ODS(2.5,1,0)',
'C1' => '=CEILING(2.5,1)',
'C2' => '=CEILING.MATH(2.5,1)',
'C3' => '=CEILING.PRECISE(2.5,1)',
'C4' => '=CEILING.ODS(2.5,1)',
'E1' => '=FLOOR.ODS(37, -1, 0)',
'F1' => '=CEILING.ODS(-37.2,1,0)',
];
private const EXPECTED_XLSX = [
'A1' => '=FLOOR(2.5,1)',
'A2' => '=FLOOR.MATH(2.5,1)',
'A3' => '=FLOOR.PRECISE(2.5,1)',
'A4' => '=FLOOR.MATH(2.5,1,0)', // note different from ODS
'C1' => '=CEILING(2.5,1)',
'C2' => '=CEILING.MATH(2.5,1)',
'C3' => '=CEILING.PRECISE(2.5,1)',
'C4' => '=CEILING.MATH(2.5,1)', // different from ODS
'E1' => '=FLOOR.MATH(37, -1, 0)', // different from ODS
'F1' => '=CEILING.MATH(-37.2,1,0)', // different from ODS
];
public function testReadAndWriteOds(): void
{
$reader = new OdsReader();
$spreadsheetOld = $reader->load(self::INFILE);
$oldSheet = $spreadsheetOld->getActiveSheet();
foreach (self::EXPECTED_ODS as $key => $value) {
self::assertSame(
$value,
$oldSheet->getCell($key)->getValue(),
"Error in cell $key"
);
}
self::assertSame('#NUM!', $oldSheet->getCell('E1')->getCalculatedValue());
self::assertSame('#NUM!', $oldSheet->getCell('F1')->getCalculatedValue());
$spreadsheet = $this->writeAndReload($spreadsheetOld, 'Ods');
$spreadsheetOld->disconnectWorksheets();
$sheet = $spreadsheet->getActiveSheet();
foreach (self::EXPECTED_ODS as $key => $value) {
self::assertSame(
$value,
$sheet->getCell($key)->getValue(),
"Error in cell $key"
);
}
self::assertSame('#NUM!', $sheet->getCell('E1')->getCalculatedValue());
self::assertSame('#NUM!', $sheet->getCell('F1')->getCalculatedValue());
$spreadsheet->disconnectWorksheets();
}
public function testReadAndWriteXlsx(): void
{
$reader = new OdsReader();
$spreadsheetOld = $reader->load(self::INFILE);
$spreadsheet = $this->writeAndReload($spreadsheetOld, 'Xlsx');
$spreadsheetOld->disconnectWorksheets();
$sheet = $spreadsheet->getActiveSheet();
foreach (self::EXPECTED_XLSX as $key => $value) {
self::assertSame(
$value,
$sheet->getCell($key)->getValue(),
"Error in cell $key"
);
}
self::assertSame(37.0, $sheet->getCell('E1')->getCalculatedValue()); // different from ODS
self::assertSame(-37.0, $sheet->getCell('F1')->getCalculatedValue()); // different from ODS
$spreadsheet->disconnectWorksheets();
}
public function testWriteXcl(): void
{
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->getCell('A1')->setValue('=CEILING.XCL(17.8,8)');
$sheet->getCell('B1')->setValue('=FLOOR.XCL(17.8,8)');
$spreadsheetOds = $this->writeAndReload($spreadsheet, 'Ods');
$sheetOds = $spreadsheetOds->getActiveSheet();
self::assertSame('=CEILING(17.8,8)', $sheetOds->getCell('A1')->getValue());
self::assertSame('=FLOOR(17.8,8)', $sheetOds->getCell('B1')->getValue());
$spreadsheetOds->disconnectWorksheets();
$spreadsheetXlsx = $this->writeAndReload($spreadsheet, 'Xlsx');
$sheetXlsx = $spreadsheetXlsx->getActiveSheet();
self::assertSame('=CEILING(17.8,8)', $sheetXlsx->getCell('A1')->getValue());
self::assertSame('=FLOOR(17.8,8)', $sheetXlsx->getCell('B1')->getValue());
$spreadsheetXlsx->disconnectWorksheets();
$spreadsheetXls = $this->writeAndReload($spreadsheet, 'Xls');
$sheetXls = $spreadsheetXls->getActiveSheet();
self::assertSame('=CEILING(17.8,8)', $sheetXls->getCell('A1')->getValue());
self::assertSame('=FLOOR(17.8,8)', $sheetXls->getCell('B1')->getValue());
$spreadsheetXls->disconnectWorksheets();
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Ods/OdsPropertiesTest.php | tests/PhpSpreadsheetTests/Reader/Ods/OdsPropertiesTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Ods;
use PhpOffice\PhpSpreadsheet\Document\Properties;
use PhpOffice\PhpSpreadsheet\Reader\Ods;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional;
class OdsPropertiesTest extends AbstractFunctional
{
private string $timeZone;
protected function setUp(): void
{
$this->timeZone = date_default_timezone_get();
date_default_timezone_set('UTC');
}
protected function tearDown(): void
{
date_default_timezone_set($this->timeZone);
}
public function testLoadOdsWorkbookProperties(): void
{
$customPropertySet = [
'Owner' => ['type' => Properties::PROPERTY_TYPE_STRING, 'value' => 'PHPOffice'],
'Tested' => ['type' => Properties::PROPERTY_TYPE_BOOLEAN, 'value' => true],
'Counter' => ['type' => Properties::PROPERTY_TYPE_FLOAT, 'value' => 10.0],
'TestDate' => ['type' => Properties::PROPERTY_TYPE_DATE, 'value' => '2019-06-30'],
'HereAndNow' => ['type' => Properties::PROPERTY_TYPE_DATE, 'value' => '2019-06-30'],
];
$filename = 'tests/data/Reader/Ods/propertyTest.ods';
$reader = new Ods();
$spreadsheet = $reader->load($filename);
$properties = $spreadsheet->getProperties();
// Core Properties
// self::assertSame('Mark Baker', $properties->getCreator());
self::assertSame('Property Test File', $properties->getTitle());
self::assertSame('Testing for Properties', $properties->getSubject());
self::assertSame('TEST ODS PHPSpreadsheet', $properties->getKeywords());
// Extended Properties
// self::assertSame('PHPOffice', $properties->getCompany());
// self::assertSame('The Big Boss', $properties->getManager());
// Custom Properties
$customProperties = $properties->getCustomProperties();
$customProperties = array_flip($customProperties);
self::assertArrayHasKey('TestDate', $customProperties);
foreach ($customPropertySet as $propertyName => $testData) {
self::assertTrue($properties->isCustomPropertySet($propertyName));
self::assertSame($testData['type'], $properties->getCustomPropertyType($propertyName));
/** @var float|int|string */
$result = $properties->getCustomPropertyValue($propertyName);
if ($properties->getCustomPropertyType($propertyName) == Properties::PROPERTY_TYPE_DATE) {
$result = Date::formattedDateTimeFromTimestamp("$result", 'Y-m-d');
}
self::assertSame($testData['value'], $result);
}
$spreadsheet->disconnectWorksheets();
}
public function testReloadOdsWorkbookProperties(): void
{
$customPropertySet = [
'Owner' => ['type' => Properties::PROPERTY_TYPE_STRING, 'value' => 'PHPOffice'],
'Tested' => ['type' => Properties::PROPERTY_TYPE_BOOLEAN, 'value' => true],
'Counter' => ['type' => Properties::PROPERTY_TYPE_FLOAT, 'value' => 10.0],
'TestDate' => ['type' => Properties::PROPERTY_TYPE_DATE, 'value' => '2019-06-30'],
'HereAndNow' => ['type' => Properties::PROPERTY_TYPE_DATE, 'value' => '2019-06-30'],
];
$filename = 'tests/data/Reader/Ods/propertyTest.ods';
$reader = new Ods();
$spreadsheetOld = $reader->load($filename);
$spreadsheet = $this->writeAndReload($spreadsheetOld, 'Ods');
$spreadsheetOld->disconnectWorksheets();
$properties = $spreadsheet->getProperties();
// Core Properties
// self::assertSame('Mark Baker', $properties->getCreator());
self::assertSame('Property Test File', $properties->getTitle());
self::assertSame('Testing for Properties', $properties->getSubject());
self::assertSame('TEST ODS PHPSpreadsheet', $properties->getKeywords());
// Extended Properties
// self::assertSame('PHPOffice', $properties->getCompany());
// self::assertSame('The Big Boss', $properties->getManager());
// Custom Properties
$customProperties = $properties->getCustomProperties();
$customProperties = array_flip($customProperties);
self::assertArrayHasKey('TestDate', $customProperties);
foreach ($customPropertySet as $propertyName => $testData) {
self::assertTrue($properties->isCustomPropertySet($propertyName));
self::assertSame($testData['type'], $properties->getCustomPropertyType($propertyName));
/** @var float|int|string */
$result = $properties->getCustomPropertyValue($propertyName);
if ($properties->getCustomPropertyType($propertyName) == Properties::PROPERTY_TYPE_DATE) {
$result = Date::formattedDateTimeFromTimestamp("$result", 'Y-m-d');
}
self::assertSame($testData['value'], $result);
}
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Ods/HiddenWorksheetTest.php | tests/PhpSpreadsheetTests/Reader/Ods/HiddenWorksheetTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Ods;
use PhpOffice\PhpSpreadsheet\Reader\Ods;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
use PHPUnit\Framework\TestCase;
class HiddenWorksheetTest extends TestCase
{
public function testPageSetup(): void
{
$filename = 'tests/data/Reader/Ods/HiddenSheet2.ods';
$reader = new Ods();
$spreadsheet = $reader->load($filename);
$assertions = $this->worksheetAssertions();
$sheetCount = 0;
foreach ($spreadsheet->getAllSheets() as $worksheet) {
if (!array_key_exists($worksheet->getTitle(), $assertions)) {
self::fail('Unexpected worksheet ' . $worksheet->getTitle());
}
++$sheetCount;
$sheetAssertions = $assertions[$worksheet->getTitle()];
foreach ($sheetAssertions as $test => $expectedResult) {
$actualResult = $worksheet->getSheetState();
self::assertSame(
$expectedResult,
$actualResult,
"Failed asserting sheet state {$expectedResult} for Worksheet '{$worksheet->getTitle()}' {$test}"
);
}
}
self::assertCount($sheetCount, $assertions);
$spreadsheet->disconnectWorksheets();
}
/** @return array<string, array<string, string>> */
private function worksheetAssertions(): array
{
return [
'Sheet1' => [
'sheetState' => Worksheet::SHEETSTATE_VISIBLE,
],
'Sheet2' => [
'sheetState' => Worksheet::SHEETSTATE_HIDDEN,
],
];
}
public function testListWorksheetInfo(): void
{
$filename = 'tests/data/Reader/Ods/HiddenSheet2.ods';
$reader = new Ods();
$expected = [
[
'worksheetName' => 'Sheet1',
'lastColumnLetter' => 'A',
'lastColumnIndex' => 0,
'totalRows' => 1,
'totalColumns' => 1,
'sheetState' => 'visible',
],
[
'worksheetName' => 'Sheet2',
'lastColumnLetter' => 'A',
'lastColumnIndex' => 0,
'totalRows' => 1,
'totalColumns' => 1,
'sheetState' => 'hidden',
],
];
self::assertSame($expected, $reader->listWorksheetInfo($filename));
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Ods/Issue4435Test.php | tests/PhpSpreadsheetTests/Reader/Ods/Issue4435Test.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Ods;
use PhpOffice\PhpSpreadsheet\Reader\Ods as OdsReader;
use PHPUnit\Framework\TestCase;
class Issue4435Test extends TestCase
{
private string $file = 'tests/data/Reader/Ods/issue.4435b.ods';
public function testNoHeaderFooterStyle(): void
{
// had been throwing exception when cell didn't have value-type
$zipFile = 'zip://' . $this->file . '#content.xml';
$contents = (string) file_get_contents($zipFile);
self::assertStringContainsString(
'<table:table-cell table:style-name="ce1">' . "\n"
. '<text:p/>' . "\n"
. '</table:table-cell>',
$contents
);
$reader = new OdsReader();
$spreadsheet = $reader->load($this->file);
$sheet = $spreadsheet->getActiveSheet();
self::assertNull($sheet->getCell('B1')->getValue());
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Ods/Issue4099Test.php | tests/PhpSpreadsheetTests/Reader/Ods/Issue4099Test.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Ods;
use PhpOffice\PhpSpreadsheet\Reader\Ods as OdsReader;
use PHPUnit\Framework\TestCase;
class Issue4099Test extends TestCase
{
private string $file = 'tests/data/Reader/Ods/issue.4099.ods';
public function testNoHeaderFooterStyle(): void
{
// header-style and footer-style are missing in styles.xml
$zipFile = 'zip://' . $this->file . '#styles.xml';
$contents = (string) file_get_contents($zipFile);
self::assertStringContainsString('page-layout ', $contents);
self::assertStringNotContainsString('header-style', $contents);
self::assertStringNotContainsString('footer-style', $contents);
$reader = new OdsReader();
$spreadsheet = $reader->load($this->file);
$sheet = $spreadsheet->getActiveSheet();
self::assertSame('FirstCell', $sheet->getCell('A1')->getValue());
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Ods/RepeatedColumnsTest.php | tests/PhpSpreadsheetTests/Reader/Ods/RepeatedColumnsTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Ods;
use PhpOffice\PhpSpreadsheet\Reader\IReadFilter;
use PhpOffice\PhpSpreadsheet\Reader\Ods;
use PHPUnit\Framework\TestCase;
class RepeatedColumnsTest extends TestCase
{
public function testDefinedNames(): void
{
$reader = new Ods();
$reader->setReadFilter(
new class () implements IReadFilter {
public function readCell(string $columnAddress, int $row, string $worksheetName = ''): bool
{
return in_array($columnAddress, ['A', 'C', 'E', 'G', 'J', 'K'], true);
}
}
);
$spreadsheet = $reader->load('tests/data/Reader/Ods/RepeatedCells.ods');
$worksheet = $spreadsheet->getActiveSheet();
self::assertEquals('TestA', $worksheet->getCell('A1')->getValue());
self::assertNull($worksheet->getCell('C1')->getValue());
self::assertEquals('TestE', $worksheet->getCell('E1')->getValue());
self::assertEquals('TestG', $worksheet->getCell('G1')->getValue());
self::assertEquals('A', $worksheet->getCell('J1')->getValue());
self::assertEquals('TestK', $worksheet->getCell('K1')->getValue());
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Ods/OdsTest.php | tests/PhpSpreadsheetTests/Reader/Ods/OdsTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Ods;
use PhpOffice\PhpSpreadsheet\Cell\DataType;
use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException;
use PhpOffice\PhpSpreadsheet\Reader\Exception as ReaderException;
use PhpOffice\PhpSpreadsheet\Reader\Ods;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\Font;
use PHPUnit\Framework\TestCase;
/**
* @TODO The class doesn't read the bold/italic/underline properties (rich text)
*/
class OdsTest extends TestCase
{
private const ODS_TEST_FILE = 'samples/templates/OOCalcTest.ods';
private const ODS_DATA_FILE = 'tests/data/Reader/Ods/data.ods';
private string $incompleteMessage = 'Features not implemented yet';
private string $timeZone;
protected function setUp(): void
{
$this->timeZone = date_default_timezone_get();
date_default_timezone_set('UTC');
}
protected function tearDown(): void
{
date_default_timezone_set($this->timeZone);
}
private function loadOdsTestFile(): Spreadsheet
{
$reader = new Ods();
return $reader->loadIntoExisting(self::ODS_TEST_FILE, new Spreadsheet());
}
protected function loadDataFile(): Spreadsheet
{
$reader = new Ods();
return $reader->load(self::ODS_DATA_FILE);
}
public function testLoadWorksheets(): void
{
$spreadsheet = $this->loadDataFile();
self::assertEquals(2, $spreadsheet->getSheetCount());
self::assertEquals('Sheet1', $spreadsheet->getSheet(0)->getTitle());
self::assertEquals('Second Sheet', $spreadsheet->getSheet(1)->getTitle());
$spreadsheet->disconnectWorksheets();
}
public function testLoadOneWorksheet(): void
{
$reader = new Ods();
//$reader->setLoadSheetsOnly(['Sheet1']);
$names = $reader->listWorksheetNames(self::ODS_DATA_FILE);
$reader->setLoadSheetsOnly([$names[0]]);
$spreadsheet = $reader->load(self::ODS_DATA_FILE);
self::assertEquals(1, $spreadsheet->getSheetCount());
self::assertEquals('Sheet1', $spreadsheet->getSheet(0)->getTitle());
$spreadsheet->disconnectWorksheets();
}
public function testLoadOneWorksheetNotActive(): void
{
$reader = new Ods();
$reader->setLoadSheetsOnly(['Second Sheet']);
$spreadsheet = $reader->load(self::ODS_DATA_FILE);
self::assertEquals(1, $spreadsheet->getSheetCount());
self::assertEquals('Second Sheet', $spreadsheet->getSheet(0)->getTitle());
$spreadsheet->disconnectWorksheets();
}
public function testLoadNoSelectedWorksheet(): void
{
$this->expectException(PhpSpreadsheetException::class);
$this->expectExceptionMessage('You tried to set a sheet active by the out of bounds index');
$reader = new Ods();
$reader->setLoadSheetsOnly(['xSecond Sheet']);
$reader->load(self::ODS_DATA_FILE);
}
public function testLoadBadFile(): void
{
$this->expectException(ReaderException::class);
$this->expectExceptionMessage('Could not find zip member');
$reader = new Ods();
$reader->load(__FILE__);
}
public function testLoadCorruptFile(): void
{
$this->expectException(ReaderException::class);
$filename = 'tests/data/Reader/Ods/corruptMeta.ods';
$reader = new Ods();
$spreadsheet = $reader->load($filename);
self::assertEquals(2, $spreadsheet->getSheetCount());
$firstSheet = $spreadsheet->getSheet(0);
$secondSheet = $spreadsheet->getSheet(1);
self::assertNotSame($firstSheet, $secondSheet);
}
public function testReadValueAndComments(): void
{
$spreadsheet = $this->loadOdsTestFile();
$firstSheet = $spreadsheet->getSheet(0);
self::assertEquals(29, $firstSheet->getHighestDataRow());
self::assertEquals('N', $firstSheet->getHighestDataColumn());
// Simple cell value
self::assertEquals('Test String 1', $firstSheet->getCell('A1')->getValue());
// Merged cell
self::assertEquals('BOX', $firstSheet->getCell('B18')->getValue());
// Comments/Annotations
self::assertEquals(
'Test for a simple colour-formatted string',
$firstSheet->getComment('A1')->getText()->getPlainText()
);
// Data types
self::assertEquals(DataType::TYPE_STRING, $firstSheet->getCell('A1')->getDataType());
self::assertEquals(DataType::TYPE_NUMERIC, $firstSheet->getCell('B1')->getDataType()); // Int
self::assertEquals(DataType::TYPE_NUMERIC, $firstSheet->getCell('B6')->getDataType()); // Float
self::assertEquals(1.23, $firstSheet->getCell('B6')->getValue());
self::assertEquals(0, $firstSheet->getCell('G10')->getValue());
self::assertEquals(DataType::TYPE_NUMERIC, $firstSheet->getCell('A10')->getDataType()); // Date
self::assertEquals('19-Dec-60', $firstSheet->getCell('A10')->getFormattedValue());
self::assertEquals(DataType::TYPE_NUMERIC, $firstSheet->getCell('A13')->getDataType()); // Time
self::assertEquals('2:30:00', $firstSheet->getCell('A13')->getFormattedValue());
self::assertEquals(DataType::TYPE_NUMERIC, $firstSheet->getCell('A15')->getDataType()); // Date + Time
self::assertEquals('19-Dec-60 1:30:00', $firstSheet->getCell('A15')->getFormattedValue());
self::assertEquals(DataType::TYPE_NUMERIC, $firstSheet->getCell('A11')->getDataType()); // Fraction
self::assertEquals(DataType::TYPE_BOOL, $firstSheet->getCell('D6')->getDataType());
self::assertTrue($firstSheet->getCell('D6')->getValue());
self::assertEquals(DataType::TYPE_FORMULA, $firstSheet->getCell('C6')->getDataType()); // Formula
self::assertEquals('=TRUE()', $firstSheet->getCell('C6')->getValue()); // Formula
$spreadsheet->disconnectWorksheets();
}
public function testReadPercentageAndCurrency(): void
{
// Percentage, Currency
$spreadsheet = $this->loadDataFile();
$firstSheet = $spreadsheet->getSheet(0);
self::assertEquals(DataType::TYPE_NUMERIC, $firstSheet->getCell('A1')->getDataType()); // Percentage (10%)
self::assertEquals(0.1, $firstSheet->getCell('A1')->getValue());
self::assertEquals(DataType::TYPE_NUMERIC, $firstSheet->getCell('A2')->getDataType()); // Percentage (10.00%)
self::assertEquals(0.1, $firstSheet->getCell('A2')->getValue());
self::assertEquals(DataType::TYPE_NUMERIC, $firstSheet->getCell('A4')->getDataType()); // Currency (€10.00)
self::assertEquals(10, $firstSheet->getCell('A4')->getValue());
self::assertEquals(DataType::TYPE_NUMERIC, $firstSheet->getCell('A5')->getDataType()); // Currency ($20)
self::assertEquals(20, $firstSheet->getCell('A5')->getValue());
$spreadsheet->disconnectWorksheets();
}
public function testReadColors(): void
{
$spreadsheet = $this->loadOdsTestFile();
$firstSheet = $spreadsheet->getSheet(0);
// Background color
$style = $firstSheet->getCell('K3')->getStyle();
self::assertEquals('none', $style->getFill()->getFillType());
self::assertEquals('FFFFFFFF', $style->getFill()->getStartColor()->getARGB());
self::assertEquals('FF000000', $style->getFill()->getEndColor()->getARGB());
$spreadsheet->disconnectWorksheets();
}
public function testReadRichText(): void
{
$spreadsheet = $this->loadOdsTestFile();
$firstSheet = $spreadsheet->getSheet(0);
self::assertEquals(
"I don't know if OOCalc supports Rich Text in the same way as Excel, "
. 'And this row should be autofit height with text wrap',
$firstSheet->getCell('A28')->getValue()
);
$spreadsheet->disconnectWorksheets();
}
public function testReadCellsWithRepeatedSpaces(): void
{
$spreadsheet = $this->loadDataFile();
$firstSheet = $spreadsheet->getSheet(0);
self::assertEquals('This has 4 spaces before and 2 after ', $firstSheet->getCell('A8')->getValue());
self::assertEquals('This only one after ', $firstSheet->getCell('A9')->getValue());
self::assertEquals('Test with DIFFERENT styles and multiple spaces: ', $firstSheet->getCell('A10')->getValue());
self::assertEquals("test with new \nLines", $firstSheet->getCell('A11')->getValue());
$spreadsheet->disconnectWorksheets();
}
public function testReadHyperlinks(): void
{
$spreadsheet = $this->loadOdsTestFile();
$firstSheet = $spreadsheet->getSheet(0);
$hyperlink = $firstSheet->getCell('A29');
self::assertEquals(DataType::TYPE_STRING, $hyperlink->getDataType());
self::assertEquals('PhpSpreadsheet', $hyperlink->getValue());
self::assertEquals('https://github.com/PHPOffice/phpspreadsheet', $hyperlink->getHyperlink()->getUrl());
$spreadsheet->disconnectWorksheets();
}
// Below some test for features not implemented yet
public function testReadBoldItalicUnderline(): void
{
if ($this->incompleteMessage !== '') {
self::markTestIncomplete($this->incompleteMessage);
}
$spreadsheet = $this->loadOdsTestFile();
$firstSheet = $spreadsheet->getSheet(0);
// Font styles
$style = $firstSheet->getCell('A1')->getStyle();
self::assertEquals('FF000000', $style->getFont()->getColor()->getARGB());
self::assertEquals(11, $style->getFont()->getSize());
self::assertEquals(Font::UNDERLINE_NONE, $style->getFont()->getUnderline());
$style = $firstSheet->getCell('E3')->getStyle();
self::assertEquals(Font::UNDERLINE_SINGLE, $style->getFont()->getUnderline());
$style = $firstSheet->getCell('E1')->getStyle();
self::assertTrue($style->getFont()->getBold());
self::assertTrue($style->getFont()->getItalic());
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Ods/InvalidFileTest.php | tests/PhpSpreadsheetTests/Reader/Ods/InvalidFileTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Ods;
use PhpOffice\PhpSpreadsheet\Reader\Exception as ReaderException;
use PhpOffice\PhpSpreadsheet\Reader\Ods;
use PHPUnit\Framework\TestCase;
class InvalidFileTest extends TestCase
{
public function testInvalidFileLoad(): void
{
$this->expectException(ReaderException::class);
$this->expectExceptionMessage('Could not find zip member');
$temp = __FILE__;
$reader = new Ods();
$reader->load($temp);
}
public function testInvalidFileNames(): void
{
$this->expectException(ReaderException::class);
$this->expectExceptionMessage('Could not find zip member');
$temp = __FILE__;
$reader = new Ods();
$reader->listWorksheetNames($temp);
}
public function testInvalidInfo(): void
{
$this->expectException(ReaderException::class);
$this->expectExceptionMessage('Could not find zip member');
$temp = __FILE__;
$reader = new Ods();
$reader->listWorksheetInfo($temp);
}
public function testXlsxFileLoad(): void
{
$this->expectException(ReaderException::class);
$this->expectExceptionMessage('Could not find zip member');
$temp = 'samples/templates/26template.xlsx';
$reader = new Ods();
$reader->load($temp);
}
public function testXlsxFileNames(): void
{
$this->expectException(ReaderException::class);
$this->expectExceptionMessage('Could not find zip member');
$temp = 'samples/templates/26template.xlsx';
$reader = new Ods();
$reader->listWorksheetNames($temp);
}
public function testXlsxInfo(): void
{
$this->expectException(ReaderException::class);
$this->expectExceptionMessage('Could not find zip member');
$temp = 'samples/templates/26template.xlsx';
$reader = new Ods();
$reader->listWorksheetInfo($temp);
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Ods/NestedTableRowTest.php | tests/PhpSpreadsheetTests/Reader/Ods/NestedTableRowTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Ods;
use PhpOffice\PhpSpreadsheet\Reader\Ods as OdsReader;
use PHPUnit\Framework\TestCase;
class NestedTableRowTest extends TestCase
{
public function testTableHeaderRows(): void
{
$infile = 'tests/data/Reader/Ods/issue.4528.ods';
$reader = new OdsReader();
$spreadsheet = $reader->load($infile);
$sheet = $spreadsheet->getActiveSheet();
self::assertSame('Atterissage', $sheet->getCell('AS1')->getValue());
self::assertNull($sheet->getCell('AS2')->getValue());
self::assertSame('jour', $sheet->getCell('AS3')->getValue());
self::assertSame('=SUM(Y3:INDIRECT(CONCATENATE("Y",$C$3)))', $sheet->getCell('AS4')->getValue());
$spreadsheet->disconnectWorksheets();
}
public function testTableRowGroup(): void
{
$infile = 'tests/data/Reader/Ods/issue.2507.ods';
$reader = new OdsReader();
$spreadsheet = $reader->load($infile);
$sheet = $spreadsheet->getActiveSheet();
$values = $sheet->rangeToArray('B3:C7', null, false, false);
$expected = [
['Номенклатура', "Складское наличие,\nКол-во"], // before table-row-group
['Квадрат 140х140мм ст.5ХНМ (т)', 0.225], // within table-row-group
['Квадрат 200х200мм ст.3 (т)', 1.700],
['Квадрат 210х210мм ст.65Г (т)', 0.280],
['Квадрат 250х250мм ст.45 (т)', 0.133],
];
self::assertSame($expected, $values);
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Ods/AutoFilterTest.php | tests/PhpSpreadsheetTests/Reader/Ods/AutoFilterTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Ods;
use PhpOffice\PhpSpreadsheet\Reader\Ods;
use PHPUnit\Framework\TestCase;
class AutoFilterTest extends TestCase
{
public function testAutoFilterRange(): void
{
$filename = 'tests/data/Reader/Ods/AutoFilter.ods';
$reader = new Ods();
$spreadsheet = $reader->load($filename);
$worksheet = $spreadsheet->getActiveSheet();
$autoFilterRange = $worksheet->getAutoFilter()->getRange();
self::assertSame('A1:C9', $autoFilterRange);
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Ods/BooleanDataTest.php | tests/PhpSpreadsheetTests/Reader/Ods/BooleanDataTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Ods;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Reader\Ods as OdsReader;
use PhpOffice\PhpSpreadsheet\Shared\File;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Ods as OdsWriter;
use PHPUnit\Framework\TestCase;
class BooleanDataTest extends TestCase
{
private string $tempfile = '';
private string $locale;
protected function setUp(): void
{
$calculation = Calculation::getInstance();
$this->locale = $calculation->getLocale();
}
protected function tearDown(): void
{
$calculation = Calculation::getInstance();
$calculation->setLocale($this->locale);
if ($this->tempfile !== '') {
unlink($this->tempfile);
$this->tempfile = '';
}
}
public function testBooleanData(): void
{
$spreadsheetOld = new Spreadsheet();
$sheetOld = $spreadsheetOld->getActiveSheet();
$sheetOld->getCell('A1')->setValue(true);
$sheetOld->getCell('A2')->setValue(false);
$writer = new OdsWriter($spreadsheetOld);
$this->tempfile = File::temporaryFileName();
$writer->save($this->tempfile);
$spreadsheetOld->disconnectWorksheets();
$reader = new OdsReader();
$spreadsheet = $reader->load($this->tempfile);
$sheet = $spreadsheet->getActiveSheet();
self::assertTrue($sheet->getCell('A1')->getValue());
self::assertFalse($sheet->getCell('A2')->getValue());
$spreadsheet->disconnectWorksheets();
$zipFile = 'zip://' . $this->tempfile . '#content.xml';
$contents = (string) file_get_contents($zipFile);
self::assertStringContainsString('<text:p>TRUE</text:p>', $contents);
self::assertStringContainsString('<text:p>FALSE</text:p>', $contents);
}
public function testBooleanDataGerman(): void
{
$calculation = Calculation::getInstance();
$calculation->setLocale('de');
$spreadsheetOld = new Spreadsheet();
$sheetOld = $spreadsheetOld->getActiveSheet();
$sheetOld->getCell('A1')->setValue(true);
$sheetOld->getCell('A2')->setValue(false);
$writer = new OdsWriter($spreadsheetOld);
$this->tempfile = File::temporaryFileName();
$writer->save($this->tempfile);
$spreadsheetOld->disconnectWorksheets();
$reader = new OdsReader();
$spreadsheet = $reader->load($this->tempfile);
$sheet = $spreadsheet->getActiveSheet();
self::assertTrue($sheet->getCell('A1')->getValue());
self::assertFalse($sheet->getCell('A2')->getValue());
$spreadsheet->disconnectWorksheets();
$zipFile = 'zip://' . $this->tempfile . '#content.xml';
$contents = (string) file_get_contents($zipFile);
self::assertStringContainsString('<text:p>WAHR</text:p>', $contents);
self::assertStringContainsString('<text:p>FALSCH</text:p>', $contents);
self::assertStringNotContainsString('<text:p>TRUE</text:p>', $contents);
self::assertStringNotContainsString('<text:p>FALSE</text:p>', $contents);
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Csv/CsvLoadFromStringTest.php | tests/PhpSpreadsheetTests/Reader/Csv/CsvLoadFromStringTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Csv;
use PhpOffice\PhpSpreadsheet\Reader\Csv;
use PHPUnit\Framework\TestCase;
class CsvLoadFromStringTest extends TestCase
{
public function testLoadFromString(): void
{
$data = <<<EOF
1,2,3
4,2+3,6
"7 , 8", 9, 10
11,"12
13",14
EOF;
$reader = new Csv();
$spreadsheet = $reader->loadSpreadsheetFromString($data);
$sheet = $spreadsheet->getActiveSheet();
self::AssertSame('2+3', $sheet->getCell('B2')->getValue());
self::AssertSame('7 , 8', $sheet->getCell('A3')->getValue());
self::AssertSame("12\n13", $sheet->getCell('B4')->getValue());
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Csv/CsvLineEndingTest.php | tests/PhpSpreadsheetTests/Reader/Csv/CsvLineEndingTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Csv;
use PhpOffice\PhpSpreadsheet\Reader\Csv;
use PhpOffice\PhpSpreadsheet\Shared\File;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class CsvLineEndingTest extends TestCase
{
private string $tempFile = '';
private static bool $alwaysFalse = false;
protected function tearDown(): void
{
if ($this->tempFile !== '') {
unlink($this->tempFile);
$this->tempFile = '';
}
}
#[DataProvider('providerEndings')]
#[DataProvider('providerEndings2')]
public function testEndings(string $ending, int $version = PHP_VERSION_ID): void
{
if ($ending === "\r" && $version >= 90000) {
self::markTestSkipped('Mac line endings not supported for Php9+');
}
$this->tempFile = $filename = File::temporaryFilename();
$data = ['123', '456', '789'];
file_put_contents($filename, implode($ending, $data));
$reader = new Csv();
if (Csv::DEFAULT_TEST_AUTODETECT === self::$alwaysFalse) {
$reader->setTestAutoDetect(true);
}
$spreadsheet = $reader->load($filename);
$sheet = $spreadsheet->getActiveSheet();
self::assertEquals($data[0], $sheet->getCell('A1')->getValue());
self::assertEquals($data[1], $sheet->getCell('A2')->getValue());
self::assertEquals($data[2], $sheet->getCell('A3')->getValue());
$spreadsheet->disconnectWorksheets();
}
#[DataProvider('providerEndings')]
public function testEndingsNoDetect(string $ending): void
{
$this->tempFile = $filename = File::temporaryFilename();
$data = ['123', '456', '789'];
file_put_contents($filename, implode($ending, $data));
$reader = new Csv();
self::assertSame(self::$alwaysFalse, Csv::DEFAULT_TEST_AUTODETECT);
$spreadsheet = $reader->load($filename);
$sheet = $spreadsheet->getActiveSheet();
if ($ending === "\r") {
// Can't handle Mac line endings without autoDetect
self::assertEquals(implode("\n", $data), $sheet->getCell('A1')->getValue());
self::assertNull($sheet->getCell('A2')->getValue());
self::assertNull($sheet->getCell('A3')->getValue());
} else {
self::assertEquals($data[0], $sheet->getCell('A1')->getValue());
self::assertEquals($data[1], $sheet->getCell('A2')->getValue());
self::assertEquals($data[2], $sheet->getCell('A3')->getValue());
}
$spreadsheet->disconnectWorksheets();
}
public static function providerEndings(): array
{
return [
'Unix endings' => ["\n"],
'Mac endings' => ["\r"],
'Windows endings' => ["\r\n"],
];
}
public static function providerEndings2(): array
{
return [
'Mac endings Php9+' => ["\r", 90000],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Csv/CsvNumberFormatTest.php | tests/PhpSpreadsheetTests/Reader/Csv/CsvNumberFormatTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Csv;
use PhpOffice\PhpSpreadsheet\Cell\DataType;
use PhpOffice\PhpSpreadsheet\Reader\Csv;
use PHPUnit\Framework\TestCase;
class CsvNumberFormatTest extends TestCase
{
protected string $filename;
protected Csv $csvReader;
protected function setUp(): void
{
$this->filename = 'tests/data/Reader/CSV/NumberFormatTest.csv';
$this->csvReader = new Csv();
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerNumberFormatNoConversionTest')]
public function testNumberFormatNoConversion(int|string $expectedValue, string $expectedFormat, string $cellAddress): void
{
$spreadsheet = $this->csvReader->load($this->filename);
$worksheet = $spreadsheet->getActiveSheet();
$cell = $worksheet->getCell($cellAddress);
self::assertSame($expectedValue, $cell->getValue(), 'Expected value check');
self::assertSame($expectedFormat, $cell->getFormattedValue(), 'Format mask check');
}
public static function providerNumberFormatNoConversionTest(): array
{
return [
[
-123,
'-123',
'A1',
],
[
'12,345.67',
'12,345.67',
'C1',
],
[
'-1,234.567',
'-1,234.567',
'A3',
],
];
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerNumberValueConversionTest')]
public function testNumberValueConversion(mixed $expectedValue, string $cellAddress): void
{
$this->csvReader->castFormattedNumberToNumeric(true);
$spreadsheet = $this->csvReader->load($this->filename);
$worksheet = $spreadsheet->getActiveSheet();
$cell = $worksheet->getCell($cellAddress);
self::assertSame(DataType::TYPE_NUMERIC, $cell->getDataType(), 'Datatype check');
self::assertSame($expectedValue, $cell->getValue(), 'Expected value check');
}
public static function providerNumberValueConversionTest(): array
{
return [
'A1' => [
-123,
'A1',
],
'B1' => [
1234,
'B1',
],
'C1' => [
12345.67,
'C1',
],
'A2' => [
123.4567,
'A2',
],
'B2' => [
123.456789012,
'B2',
],
'A3' => [
-1234.567,
'A3',
],
'B3' => [
1234.567,
'B3',
],
];
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerNumberFormatConversionTest')]
public function testNumberFormatConversion(mixed $expectedValue, string $expectedFormat, string $cellAddress): void
{
$this->csvReader->castFormattedNumberToNumeric(true, true);
$spreadsheet = $this->csvReader->load($this->filename);
$worksheet = $spreadsheet->getActiveSheet();
$cell = $worksheet->getCell($cellAddress);
self::assertSame(DataType::TYPE_NUMERIC, $cell->getDataType(), 'Datatype check');
self::assertSame($expectedValue, $cell->getValue(), 'Expected value check');
self::assertSame($expectedFormat, $cell->getFormattedValue(), 'Format mask check');
}
public static function providerNumberFormatConversionTest(): array
{
return [
'A1' => [
-123,
'-123',
'A1',
],
'B1' => [
1234,
'1,234',
'B1',
],
'C1' => [
12345.67,
'12,345.67',
'C1',
],
'A2' => [
123.4567,
'123.4567',
'A2',
],
'B2' => [
123.456789012,
'123.456789',
'B2',
],
'A3' => [
-1234.567,
'-1,234.567',
'A3',
],
'B3' => [
1234.567,
'1234.567',
'B3',
],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Csv/CsvTest.php | tests/PhpSpreadsheetTests/Reader/Csv/CsvTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Csv;
use PhpOffice\PhpSpreadsheet\Reader\Csv;
use PhpOffice\PhpSpreadsheet\Reader\Exception as ReaderException;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class CsvTest extends TestCase
{
#[DataProvider('providerDelimiterDetection')]
public function testDelimiterDetection(string $filename, string $expectedDelimiter, string $cell, string|float|int|null $expectedValue): void
{
$reader = new Csv();
$delim1 = $reader->getDelimiter();
self::assertNull($delim1);
$spreadsheet = $reader->load($filename);
self::assertSame($expectedDelimiter, $reader->getDelimiter(), 'should be able to infer the delimiter');
$actual = $spreadsheet->getActiveSheet()->getCell($cell)->getValue();
self::assertSame($expectedValue, $actual, 'should be able to retrieve correct value');
}
public static function providerDelimiterDetection(): array
{
return [
[
'tests/data/Reader/CSV/enclosure.csv',
',',
'C4',
'username2',
],
[
'tests/data/Reader/CSV/semicolon_separated.csv',
';',
'C2',
'25,5',
],
[
'tests/data/Reader/CSV/line_break_in_enclosure.csv',
',',
'A3',
'Test',
],
[
'tests/data/Reader/CSV/line_break_in_enclosure_with_escaped_quotes.csv',
',',
'A3',
'Test',
],
[
'tests/data/Reader/HTML/csv_with_angle_bracket.csv',
',',
'B1',
'Number of items with weight <= 50kg',
],
[
'samples/Reader2/sampleData/example1.csv',
',',
'I4',
'100%',
],
[
'samples/Reader2/sampleData/example2.csv',
',',
'D8',
-58.373161,
],
[
'tests/data/Reader/CSV/empty.csv',
',',
'A1',
null,
],
[
'tests/data/Reader/CSV/no_delimiter.csv',
',',
'A1',
'SingleLine',
],
];
}
#[DataProvider('providerCanLoad')]
public function testCanLoad(bool $expected, string $filename): void
{
$reader = new Csv();
self::assertSame($expected, $reader->canRead($filename));
}
public static function providerCanLoad(): array
{
return [
[false, 'tests/data/Reader/Ods/data.ods'],
[false, 'samples/templates/excel2003.xml'],
[true, 'tests/data/Reader/CSV/enclosure.csv'],
[true, 'tests/data/Reader/CSV/semicolon_separated.csv'],
[true, 'tests/data/Reader/CSV/contains_html.csv'],
[true, 'tests/data/Reader/CSV/csv_without_extension'],
[true, 'tests/data/Reader/HTML/csv_with_angle_bracket.csv'],
[true, 'tests/data/Reader/CSV/empty.csv'],
[true, 'samples/Reader2/sampleData/example1.csv'],
[true, 'samples/Reader2/sampleData/example2.csv'],
];
}
#[DataProvider('providerVersion')]
public function testEscapeCharacters(int $version): void
{
if ($version >= 90000) {
$this->expectException(ReaderException::class);
$this->expectExceptionMessage('Escape character must be null string');
}
$reader = new Csv();
if ($version === PHP_VERSION_ID) {
$reader->setEscapeCharacter('"');
} else {
$reader->setEscapeCharacter('"', $version);
}
$worksheet = $reader->load('tests/data/Reader/CSV/backslash.csv')
->getActiveSheet();
$expected = [
['field 1', 'field 2\\'],
['field 3\\', 'field 4'],
];
self::assertSame('"', $reader->getEscapeCharacter());
self::assertSame($expected, $worksheet->toArray());
}
public static function providerVersion(): array
{
return [
[PHP_VERSION_ID],
[90000],
];
}
public function testInvalidWorkSheetInfo(): void
{
$this->expectException(ReaderException::class);
$reader = new Csv();
$reader->listWorksheetInfo('');
}
public function testUtf16LineBreak(): void
{
$reader = new Csv();
$reader->setInputEncoding('UTF-16BE');
$spreadsheet = $reader->load('tests/data/Reader/CSV/utf16be.line_break_in_enclosure.csv');
$sheet = $spreadsheet->getActiveSheet();
$expected = <<<EOF
This is a test
with line breaks
that breaks the
delimiters
EOF;
self::assertEquals($expected, $sheet->getCell('B3')->getValue());
}
public function testLineBreakEscape(): void
{
$reader = new Csv();
$spreadsheet = $reader->load('tests/data/Reader/CSV/line_break_in_enclosure_with_escaped_quotes.csv');
$sheet = $spreadsheet->getActiveSheet();
$expected = <<<EOF
This is a "test csv file"
with both "line breaks"
and "escaped
quotes" that breaks
the delimiters
EOF;
self::assertEquals($expected, $sheet->getCell('B3')->getValue());
}
public function testUtf32LineBreakEscape(): void
{
$reader = new Csv();
$reader->setInputEncoding('UTF-32LE');
$spreadsheet = $reader->load('tests/data/Reader/CSV/line_break_escaped_32le.csv');
$sheet = $spreadsheet->getActiveSheet();
$expected = <<<EOF
This is a "test csv file"
with both "line breaks"
and "escaped
quotes" that breaks
the delimiters
EOF;
self::assertEquals($expected, $sheet->getCell('B3')->getValue());
}
public function testSeparatorLine(): void
{
$reader = new Csv();
$reader->setSheetIndex(3);
$spreadsheet = $reader->load('tests/data/Reader/CSV/sep.csv');
self::assertEquals(';', $reader->getDelimiter());
$sheet = $spreadsheet->getActiveSheet();
self::assertEquals(3, $reader->getSheetIndex());
self::assertEquals(3, $spreadsheet->getActiveSheetIndex());
self::assertEquals('A', $sheet->getCell('A1')->getValue());
self::assertEquals(1, $sheet->getCell('B1')->getValue());
self::assertEquals(2, $sheet->getCell('A2')->getValue());
self::assertEquals(3, $sheet->getCell('B2')->getValue());
}
public function testDefaultSettings(): void
{
$reader = new Csv();
self::assertEquals('UTF-8', $reader->getInputEncoding());
self::assertEquals('"', $reader->getEnclosure());
$reader->setEnclosure('\'');
self::assertEquals('\'', $reader->getEnclosure());
$reader->setEnclosure('');
self::assertEquals('"', $reader->getEnclosure());
// following tests from BaseReader
self::assertTrue($reader->getReadEmptyCells());
self::assertFalse($reader->getIncludeCharts());
self::assertNull($reader->getLoadSheetsOnly());
}
public function testReadEmptyFileName(): void
{
$this->expectException(ReaderException::class);
$reader = new Csv();
$filename = '';
$reader->load($filename);
}
public function testReadNonexistentFileName(): void
{
$this->expectException(ReaderException::class);
$reader = new Csv();
$reader->load('tests/data/Reader/CSV/encoding.utf8.csvxxx');
}
#[DataProvider('providerEscapes')]
public function testInferSeparator(string $escape, string $delimiter, int $version = PHP_VERSION_ID): void
{
if ($version >= 90000 && $escape !== '') {
$this->expectException(ReaderException::class);
$this->expectExceptionMessage('Escape character must be null string');
}
$reader = new Csv();
if ($version === PHP_VERSION_ID) {
$reader->setEscapeCharacter($escape);
} else {
$reader->setEscapeCharacter($escape, $version);
}
$filename = 'tests/data/Reader/CSV/escape.csv';
$reader->listWorksheetInfo($filename);
self::assertEquals($delimiter, $reader->getDelimiter());
}
public static function providerEscapes(): array
{
return [
['\\', ';'],
["\x0", ','],
['', ','],
['\\', ';', 90000],
];
}
public function testSetDelimiterNull(): void
{
$reader = new Csv();
$reader->setDelimiter(',');
self::assertSame(',', $reader->getDelimiter());
$reader->setDelimiter(null);
self::assertNull($reader->getDelimiter());
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Csv/CsvIssue2840Test.php | tests/PhpSpreadsheetTests/Reader/Csv/CsvIssue2840Test.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Csv;
use PhpOffice\PhpSpreadsheet\Reader\Csv;
use PHPUnit\Framework\TestCase;
class CsvIssue2840Test extends TestCase
{
public function testNullStringIgnore(): void
{
$reader = new Csv();
self::assertFalse($reader->getPreserveNullString());
$inputData = <<<EOF
john,,doe,,
mary,,jane,,
EOF;
$expected = [
['john', null, 'doe'],
['mary', null, 'jane'],
];
$spreadsheet = $reader->loadSpreadsheetFromString($inputData);
$sheet = $spreadsheet->getActiveSheet();
self::assertSame($expected, $sheet->toArray());
$spreadsheet->disconnectWorksheets();
}
public function testNullStringLoad(): void
{
$reader = new Csv();
$reader->setPreserveNullString(true);
$inputData = <<<EOF
john,,doe,,
mary,,jane,,
EOF;
$expected = [
['john', '', 'doe', '', ''],
['mary', '', 'jane', '', ''],
];
$spreadsheet = $reader->loadSpreadsheetFromString($inputData);
$sheet = $spreadsheet->getActiveSheet();
self::assertSame($expected, $sheet->toArray());
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Csv/CsvNumberFormatLocaleTest.php | tests/PhpSpreadsheetTests/Reader/Csv/CsvNumberFormatLocaleTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Csv;
use PhpOffice\PhpSpreadsheet\Cell\DataType;
use PhpOffice\PhpSpreadsheet\Reader\Csv;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class CsvNumberFormatLocaleTest extends TestCase
{
private bool $localeAdjusted;
/**
* @var false|string
*/
private $currentLocale;
protected string $filename;
protected Csv $csvReader;
protected function setUp(): void
{
$this->currentLocale = setlocale(LC_ALL, '0');
if (!setlocale(LC_ALL, 'de_DE.UTF-8', 'deu_deu.utf8')) {
$this->localeAdjusted = false;
return;
}
$this->localeAdjusted = true;
$this->filename = 'tests/data/Reader/CSV/NumberFormatTest.de.csv';
$this->csvReader = new Csv();
StringHelper::setCurrencyCode(null);
StringHelper::setThousandsSeparator(null);
StringHelper::setDecimalSeparator(null);
}
protected function tearDown(): void
{
StringHelper::setCurrencyCode(null);
StringHelper::setThousandsSeparator(null);
StringHelper::setDecimalSeparator(null);
if ($this->localeAdjusted && is_string($this->currentLocale)) {
setlocale(LC_ALL, $this->currentLocale);
}
}
#[DataProvider('providerNumberFormatNoConversionTest')]
public function testNumberFormatNoConversion(mixed $expectedValue, string $expectedFormat, string $cellAddress): void
{
if (!$this->localeAdjusted) {
self::markTestSkipped('Unable to set locale for testing.');
}
$localeconv = localeconv();
self::assertSame(',', $localeconv['decimal_point'], 'unexpected change to German decimal separator');
self::assertSame('.', $localeconv['thousands_sep'], 'unexpected change to German thousands separator');
$spreadsheet = $this->csvReader->load($this->filename);
$worksheet = $spreadsheet->getActiveSheet();
$cell = $worksheet->getCell($cellAddress);
self::assertSame($expectedValue, $cell->getValue(), 'Expected value check');
self::assertSame($expectedFormat, $cell->getFormattedValue(), 'Format mask check');
}
public static function providerNumberFormatNoConversionTest(): array
{
return [
[
-123,
'-123',
'A1',
],
[
'12.345,67',
'12.345,67',
'C1',
],
[
'-1.234,567',
'-1.234,567',
'A3',
],
];
}
#[DataProvider('providerNumberValueConversionTest')]
public function testNumberValueConversion(mixed $expectedValue, string $cellAddress): void
{
if (!$this->localeAdjusted) {
self::markTestSkipped('Unable to set locale for testing.');
}
$localeconv = localeconv();
self::assertSame(',', $localeconv['decimal_point'], 'unexpected change to German decimal separator');
self::assertSame('.', $localeconv['thousands_sep'], 'unexpected change to German thousands separator');
$this->csvReader->castFormattedNumberToNumeric(true);
$spreadsheet = $this->csvReader->load($this->filename);
$worksheet = $spreadsheet->getActiveSheet();
$cell = $worksheet->getCell($cellAddress);
self::assertSame(DataType::TYPE_NUMERIC, $cell->getDataType(), 'Datatype check');
self::assertSame($expectedValue, $cell->getValue(), 'Expected value check');
}
public static function providerNumberValueConversionTest(): array
{
return [
'A1' => [
-123,
'A1',
],
'B1' => [
1234,
'B1',
],
'C1' => [
12345.67,
'C1',
],
'A2' => [
123.4567,
'A2',
],
'B2' => [
123.456789012,
'B2',
],
'A3' => [
-1234.567,
'A3',
],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Csv/CsvContiguousFilter.php | tests/PhpSpreadsheetTests/Reader/Csv/CsvContiguousFilter.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Csv;
use PhpOffice\PhpSpreadsheet\Reader\IReadFilter;
/** Define a Read Filter class implementing IReadFilter */
class CsvContiguousFilter implements IReadFilter
{
private int $startRow = 0;
private int $endRow = 0;
private int $filterType = 0;
/**
* Set the list of rows that we want to read.
*/
public function setRows(int $startRow, int $chunkSize): void
{
$this->startRow = $startRow;
$this->endRow = $startRow + $chunkSize;
}
public function setFilterType(int $type): void
{
$this->filterType = $type;
}
public function filter1(int $row): bool
{
// Include rows 1-10, followed by 100-110, etc.
return $row % 100 <= 10;
}
public function filter0(int $row): bool
{
// Only read the heading row, and the rows that are configured in $this->_startRow and $this->_endRow
if (($row == 1) || ($row >= $this->startRow && $row < $this->endRow)) {
return true;
}
return false;
}
public function readCell(string $columnAddress, int $row, string $worksheetName = ''): bool
{
if ($this->filterType == 1) {
return $this->filter1($row);
}
return $this->filter0($row);
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Csv/CsvCallbackTest.php | tests/PhpSpreadsheetTests/Reader/Csv/CsvCallbackTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Csv;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Reader\Csv;
use PHPUnit\Framework\TestCase;
class CsvCallbackTest extends TestCase
{
protected function tearDown(): void
{
Csv::setConstructorCallback(null);
}
public function callbackDoNothing(mixed $obj): void
{
self::assertInstanceOf(Csv::class, $obj);
}
public function testCallbackDoNothing(): void
{
Csv::setConstructorCallback([$this, 'callbackDoNothing']);
$filename = 'tests/data/Reader/CSV/encoding.iso88591.csv';
$reader = new Csv();
$reader->setInputEncoding(Csv::GUESS_ENCODING);
$spreadsheet = $reader->load($filename);
$sheet = $spreadsheet->getActiveSheet();
self::assertEquals('Å', $sheet->getCell('A1')->getValue());
$spreadsheet->disconnectWorksheets();
}
public function callbackSetFallbackEncoding(Csv $reader): void
{
$reader->setFallbackEncoding('ISO-8859-2');
$reader->setInputEncoding(Csv::GUESS_ENCODING);
$reader->setSheetNameIsFileName(true);
$reader->setEscapeCharacter('');
}
public function testFallbackEncodingDefltIso2(): void
{
Csv::setConstructorCallback([$this, 'callbackSetFallbackEncoding']);
$filename = 'tests/data/Reader/CSV/premiere.win1252.csv';
$reader = new Csv();
$spreadsheet = $reader->load($filename);
$sheet = $spreadsheet->getActiveSheet();
self::assertEquals('premičre', $sheet->getCell('A1')->getValue());
self::assertEquals('sixičme', $sheet->getCell('C2')->getValue());
$spreadsheet->disconnectWorksheets();
}
public function testIOFactory(): void
{
Csv::setConstructorCallback([$this, 'callbackSetFallbackEncoding']);
$filename = 'tests/data/Reader/CSV/premiere.win1252.csv';
$spreadsheet = IOFactory::load($filename);
$sheet = $spreadsheet->getActiveSheet();
self::assertEquals('premičre', $sheet->getCell('A1')->getValue());
self::assertEquals('sixičme', $sheet->getCell('C2')->getValue());
$spreadsheet->disconnectWorksheets();
}
public function testNonFallbackEncoding(): void
{
Csv::setConstructorCallback([$this, 'callbackSetFallbackEncoding']);
$filename = 'tests/data/Reader/CSV/premiere.utf16be.csv';
$reader = new Csv();
$spreadsheet = $reader->load($filename);
$sheet = $spreadsheet->getActiveSheet();
self::assertEquals('première', $sheet->getCell('A1')->getValue());
self::assertEquals('sixième', $sheet->getCell('C2')->getValue());
$spreadsheet->disconnectWorksheets();
}
public function testDefaultEscape(): void
{
self::assertNull(Csv::getConstructorCallback());
$filename = 'tests/data/Reader/CSV/escape.csv';
$spreadsheet = IOFactory::load($filename);
$sheet = $spreadsheet->getActiveSheet();
// this is not how Excel views the file
self::assertEquals('a\"hello', $sheet->getCell('A1')->getValue());
$spreadsheet->disconnectWorksheets();
}
public function testBetterEscape(): void
{
Csv::setConstructorCallback([$this, 'callbackSetFallbackEncoding']);
$filename = 'tests/data/Reader/CSV/escape.csv';
$spreadsheet = IOFactory::load($filename);
$sheet = $spreadsheet->getActiveSheet();
// this is how Excel views the file
self::assertEquals('a\"hello;hello;hello;\"', $sheet->getCell('A1')->getValue());
self::assertSame('escape', $sheet->getTitle(), 'callback set sheet title to use file name rather than default');
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Csv/Php9Test.php | tests/PhpSpreadsheetTests/Reader/Csv/Php9Test.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Csv;
use PhpOffice\PhpSpreadsheet\Reader\Csv;
use PhpOffice\PhpSpreadsheet\Reader\Exception as ReaderException;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class Php9Test extends TestCase
{
#[DataProvider('providerVersion')]
public function testAffectedByPhp9(int $version): void
{
if ($version >= 90000) {
$this->expectException(ReaderException::class);
$this->expectExceptionMessage('Php7.4 or Php8');
}
$dir = 'tests/data/Reader/CSV';
$files = glob("$dir/*");
self::assertNotFalse($files);
$affected = [];
foreach ($files as $file) {
$base = basename($file);
$encoding = 'UTF-8';
if (str_contains($base, 'utf') && !str_contains($base, 'bom')) {
$encoding = 'guess';
}
$result = Csv::affectedByPhp9($file, $encoding, version: $version);
if ($result) {
$affected[] = $base;
}
}
$expected = ['backslash.csv', 'escape.csv', 'linend.mac.csv'];
self::assertSame($expected, $affected);
}
public static function providerVersion(): array
{
return [
[PHP_VERSION_ID],
[90000],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Csv/NotHtmlTest.php | tests/PhpSpreadsheetTests/Reader/Csv/NotHtmlTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Csv;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Reader\Csv as CsvReader;
use PhpOffice\PhpSpreadsheet\Shared\File;
use PHPUnit\Framework\TestCase;
class NotHtmlTest extends TestCase
{
private string $tempFile = '';
protected function tearDown(): void
{
if ($this->tempFile !== '') {
unlink($this->tempFile);
$this->tempFile = '';
}
}
public function testHtmlCantRead(): void
{
// This test has a file which IOFactory will identify as Csv.
// So file can be read using either Csv Reader or IOFactory.
$this->tempFile = $filename = File::temporaryFilename();
$cells = [
['1', '<a href="http://example.com">example</a>', '3'],
['4', '5', '6'],
];
$handle = fopen($filename, 'wb');
self::assertNotFalse($handle);
foreach ($cells as $row) {
fwrite($handle, "{$row[0]},{$row[1]},{$row[2]}\n");
}
fclose($handle);
// Php8.3- identify file as text/html.
// Php8.4+ identify file as text/csv, and this type of change
// has been known to be retrofitted to prior versions.
$mime = mime_content_type($filename);
if ($mime !== 'text/csv') {
self::assertSame('text/html', $mime);
}
self::assertSame('Csv', IOFactory::identify($filename));
$reader = new CsvReader();
$spreadsheet = $reader->load($filename);
$sheet = $spreadsheet->getActiveSheet();
self::assertSame($cells, $sheet->toArray());
$spreadsheet->disconnectWorksheets();
}
public function testHtmlCanRead(): void
{
// This test has a file which IOFactory will identify as Html.
// So file has to be read using Csv Reader, not IOFactory.
$this->tempFile = $filename = File::temporaryFilename();
$cells = [
['<a href="http://example.com">example</a>', '<div>hello', '3'],
['4', '5', '</div>'],
];
$handle = fopen($filename, 'wb');
self::assertNotFalse($handle);
foreach ($cells as $row) {
fwrite($handle, "{$row[0]},{$row[1]},{$row[2]}\n");
}
fclose($handle);
// Php8.3- identify file as text/html.
// Php8.4+ identify file as text/csv, and this type of change
// has been known to be retrofitted to prior versions.
$mime = mime_content_type($filename);
if ($mime !== 'text/csv') {
self::assertSame('text/html', $mime);
}
self::assertSame('Html', IOFactory::identify($filename));
$reader = new CsvReader();
$spreadsheet = $reader->load($filename);
$sheet = $spreadsheet->getActiveSheet();
self::assertSame($cells, $sheet->toArray());
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Csv/CsvIssue2232Test.php | tests/PhpSpreadsheetTests/Reader/Csv/CsvIssue2232Test.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Csv;
use PhpOffice\PhpSpreadsheet\Cell\Cell;
use PhpOffice\PhpSpreadsheet\Cell\IValueBinder;
use PhpOffice\PhpSpreadsheet\Cell\StringValueBinder;
use PhpOffice\PhpSpreadsheet\Reader\Csv;
use PhpOffice\PhpSpreadsheet\Settings;
use PHPUnit\Framework\TestCase;
class CsvIssue2232Test extends TestCase
{
private IValueBinder $valueBinder;
private string $locale;
protected function setUp(): void
{
$this->valueBinder = Cell::getValueBinder();
$this->locale = Settings::getLocale();
}
protected function tearDown(): void
{
Cell::setValueBinder($this->valueBinder);
Settings::setLocale($this->locale);
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerIssue2232')]
public function testBooleanConversions(bool $useStringBinder, ?bool $preserveBoolString, bool|string $b2Value, bool|string $b3Value): void
{
if ($useStringBinder) {
$binder = new StringValueBinder();
if (is_bool($preserveBoolString)) {
$binder->setBooleanConversion($preserveBoolString);
}
Cell::setValueBinder($binder);
}
$reader = new Csv();
$filename = 'tests/data/Reader/CSV/issue.2232.csv';
$spreadsheet = $reader->load($filename);
$sheet = $spreadsheet->getActiveSheet();
self::assertSame($b2Value, $sheet->getCell('B2')->getValue());
self::assertSame($b3Value, $sheet->getCell('B3')->getValue());
$spreadsheet->disconnectWorksheets();
}
public static function providerIssue2232(): array
{
return [
[false, false, false, true],
[false, null, false, true],
[false, true, false, true],
[true, false, false, true],
[true, null, 'FaLSe', 'tRUE'],
[true, true, 'FaLSe', 'tRUE'],
];
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerIssue2232locale')]
public function testBooleanConversionsLocaleAware(bool $useStringBinder, ?bool $preserveBoolString, mixed $b2Value, mixed $b3Value, mixed $b4Value, mixed $b5Value): void
{
if ($useStringBinder) {
$binder = new StringValueBinder();
if (is_bool($preserveBoolString)) {
$binder->setBooleanConversion($preserveBoolString);
}
Cell::setValueBinder($binder);
}
Settings::setLocale('fr');
$reader = new Csv();
$filename = 'tests/data/Reader/CSV/issue.2232.csv';
$spreadsheet = $reader->load($filename);
$sheet = $spreadsheet->getActiveSheet();
self::assertSame($b2Value, $sheet->getCell('B2')->getValue());
self::assertSame($b3Value, $sheet->getCell('B3')->getValue());
self::assertSame($b4Value, $sheet->getCell('B4')->getValue());
self::assertSame($b5Value, $sheet->getCell('B5')->getValue());
$spreadsheet->disconnectWorksheets();
}
public static function providerIssue2232locale(): array
{
return [
'string binder preserve boolean string' => [true, true, 'FaLSe', 'tRUE', 'Faux', 'Vrai'],
'string binder convert boolean string' => [true, false, false, true, false, true],
'default binder' => [false, null, false, true, false, true],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Csv/CsvContiguousTest.php | tests/PhpSpreadsheetTests/Reader/Csv/CsvContiguousTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Csv;
use PhpOffice\PhpSpreadsheet\Reader\Csv;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase;
class CsvContiguousTest extends TestCase
{
private string $inputFileName = 'samples/Reader2/sampleData/example2.csv';
public function testContiguous(): void
{
// Create a new Reader of the type defined in $inputFileType
$reader = new Csv();
// Define how many rows we want to read for each "chunk"
$chunkSize = 100;
// Create a new Instance of our Read Filter
$chunkFilter = new CsvContiguousFilter();
// Tell the Reader that we want to use the Read Filter that we've Instantiated
// and that we want to store it in contiguous rows/columns
self::assertFalse($reader->getContiguous());
$reader->setReadFilter($chunkFilter);
$reader->setContiguous(true);
// Instantiate a new PhpSpreadsheet object manually
$spreadsheet = new Spreadsheet();
// Set a sheet index
$sheet = 0;
// Loop to read our worksheet in "chunk size" blocks
/** $startRow is set to 2 initially because we always read the headings in row #1 * */
for ($startRow = 2; $startRow <= 240; $startRow += $chunkSize) {
// Tell the Read Filter, the limits on which rows we want to read this iteration
$chunkFilter->setRows($startRow, $chunkSize);
// Increment the worksheet index pointer for the Reader
$reader->setSheetIndex($sheet);
// Load only the rows that match our filter into a new worksheet in the PhpSpreadsheet Object
$reader->loadIntoExisting($this->inputFileName, $spreadsheet);
// Set the worksheet title (to reference the "sheet" of data that we've loaded)
// and increment the sheet index as well
$spreadsheet->getActiveSheet()->setTitle('Country Data #' . (++$sheet));
}
self::assertSame('Kabul', self::getCellValue($spreadsheet, 'Country Data #1', 'A2'));
self::assertSame('Lesotho', self::getCellValue($spreadsheet, 'Country Data #2', 'B4'));
self::assertSame('-20.1', self::getCellValue($spreadsheet, 'Country Data #3', 'C6'));
}
private static function getCellValue(Spreadsheet $spreadsheet, string $sheetName, string $cellAddress): string
{
$sheet = $spreadsheet->getSheetByNameOrThrow($sheetName);
$result = '';
$value = $sheet->getCell($cellAddress)->getValue();
if (is_scalar($value) || (is_object($value) && method_exists($value, '__toString'))) {
$result = (string) $value;
}
return $result;
}
public function testContiguous2(): void
{
// Create a new Reader of the type defined in $inputFileType
$reader = new Csv();
// Create a new Instance of our Read Filter
$chunkFilter = new CsvContiguousFilter();
$chunkFilter->setFilterType(1);
// Tell the Reader that we want to use the Read Filter that we've Instantiated
// and that we want to store it in contiguous rows/columns
$reader->setReadFilter($chunkFilter);
$reader->setContiguous(true);
// Instantiate a new PhpSpreadsheet object manually
$spreadsheet = new Spreadsheet();
// Loop to read our worksheet in "chunk size" blocks
$reader->loadIntoExisting($this->inputFileName, $spreadsheet);
$sheet = $spreadsheet->getActiveSheet();
self::assertEquals('Kabul', $sheet->getCell('A2')->getValue());
self::assertEquals('Kuwait', $sheet->getCell('B11')->getValue());
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Csv/BinderTest.php | tests/PhpSpreadsheetTests/Reader/Csv/BinderTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Csv;
use PhpOffice\PhpSpreadsheet\Cell\DataType;
use PhpOffice\PhpSpreadsheet\Cell\StringValueBinder;
use PhpOffice\PhpSpreadsheet\Reader\Csv;
use PHPUnit\Framework\TestCase;
class BinderTest extends TestCase
{
public function testLoadFromString(): void
{
$data = <<<EOF
1,2,3
4,5,6
EOF;
$reader1 = new Csv();
$spreadsheet1 = $reader1->loadSpreadsheetFromString($data);
$sheet1 = $spreadsheet1->getActiveSheet();
$sheet1->getCell('A3')->setValueExplicit(7, DataType::TYPE_STRING);
$sheet1->getCell('B3')->setValueExplicit(8, DataType::TYPE_NUMERIC);
$sheet1->setCellValue('C3', 9);
$sheet1->fromArray([10, 11, 12], null, 'A4');
$expected1 = [
[1, 2, 3],
[4, 5, 6],
['7', 8, 9],
[10, 11, 12],
];
self::AssertSame($expected1, $sheet1->toArray(null, false, false));
$reader2 = new Csv();
$reader2->setValueBinder(new StringValueBinder());
self::assertInstanceOf(StringValueBinder::class, $reader2->getValueBinder());
$spreadsheet2 = $reader2->loadSpreadsheetFromString($data);
$sheet2 = $spreadsheet2->getActiveSheet();
$sheet2->getCell('A3')->setValueExplicit(7, DataType::TYPE_STRING);
$sheet2->getCell('B3')->setValueExplicit(8, DataType::TYPE_NUMERIC);
$sheet2->setCellValue('C3', 9);
$sheet2->fromArray([10, 11, 12], null, 'A4');
$expected2 = [
['1', '2', '3'],
['4', '5', '6'],
['7', 8, '9'],
['10', '11', '12'],
];
self::AssertSame($expected2, $sheet2->toArray(null, false, false));
$spreadsheet1->disconnectWorksheets();
$spreadsheet2->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Csv/CsvEncodingTest.php | tests/PhpSpreadsheetTests/Reader/Csv/CsvEncodingTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Csv;
use PhpOffice\PhpSpreadsheet\Reader\Csv;
use PHPUnit\Framework\TestCase;
class CsvEncodingTest extends TestCase
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerEncodings')]
public function testEncodings(string $filename, string $encoding): void
{
$reader = new Csv();
$reader->setInputEncoding($encoding);
$spreadsheet = $reader->load($filename);
$sheet = $spreadsheet->getActiveSheet();
self::assertEquals('Å', $sheet->getCell('A1')->getValue());
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerEncodings')]
public function testWorkSheetInfo(string $filename, string $encoding): void
{
$reader = new Csv();
$reader->setInputEncoding($encoding);
$info = $reader->listWorksheetInfo($filename);
self::assertCount(1, $info);
self::assertSame('Worksheet', $info[0]['worksheetName']);
self::assertSame('B', $info[0]['lastColumnLetter']);
self::assertSame(1, $info[0]['lastColumnIndex']);
self::assertSame(2, $info[0]['totalRows']);
self::assertSame(2, $info[0]['totalColumns']);
self::assertSame(['Worksheet'], $reader->listWorksheetNames($filename));
}
public static function providerEncodings(): array
{
return [
['tests/data/Reader/CSV/encoding.iso88591.csv', 'ISO-8859-1'],
['tests/data/Reader/CSV/encoding.utf8.csv', 'UTF-8'],
['tests/data/Reader/CSV/encoding.utf8bom.csv', 'UTF-8'],
['tests/data/Reader/CSV/encoding.utf16be.csv', 'UTF-16BE'],
['tests/data/Reader/CSV/encoding.utf16le.csv', 'UTF-16LE'],
['tests/data/Reader/CSV/encoding.utf32be.csv', 'UTF-32BE'],
['tests/data/Reader/CSV/encoding.utf32le.csv', 'UTF-32LE'],
];
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerGuessEncoding')]
public function testGuessEncoding(string $filename): void
{
$reader = new Csv();
$reader->setInputEncoding(Csv::guessEncoding($filename));
$spreadsheet = $reader->load($filename);
$sheet = $spreadsheet->getActiveSheet();
self::assertEquals('première', $sheet->getCell('A1')->getValue());
self::assertEquals('sixième', $sheet->getCell('C2')->getValue());
}
public function testSurrogate(): void
{
// Surrogates should occur only in UTF-16, and should
// be properly converted to UTF8 when read.
// FFFE/FFFF are illegal, and should be converted to
// substitution character when read.
// Excel does not handle any of the cells in row 3 well.
// LibreOffice handles A3 fine, and discards B3/C3,
// which is a reasonable action.
$filename = 'tests/data/Reader/CSV/premiere.utf16le.csv';
$reader = new Csv();
$reader->setInputEncoding(Csv::guessEncoding($filename));
$names = $reader->listWorksheetNames($filename);
// Following ignored, just make sure it's executable.
$reader->setLoadSheetsOnly([$names[0]]);
$spreadsheet = $reader->load($filename);
$sheet = $spreadsheet->getActiveSheet();
self::assertEquals('𐐀', $sheet->getCell('A3')->getValue());
self::assertEquals('�', $sheet->getCell('B3')->getValue());
self::assertEquals('�', $sheet->getCell('C3')->getValue());
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerGuessEncoding')]
public function testFallbackEncoding(string $filename): void
{
$reader = new Csv();
$reader->setInputEncoding(Csv::GUESS_ENCODING);
$spreadsheet = $reader->load($filename);
$sheet = $spreadsheet->getActiveSheet();
self::assertEquals('première', $sheet->getCell('A1')->getValue());
self::assertEquals('sixième', $sheet->getCell('C2')->getValue());
}
public static function providerGuessEncoding(): array
{
return [
['tests/data/Reader/CSV/premiere.utf8.csv'],
['tests/data/Reader/CSV/premiere.utf8bom.csv'],
['tests/data/Reader/CSV/premiere.utf16be.csv'],
['tests/data/Reader/CSV/premiere.utf16bebom.csv'],
['tests/data/Reader/CSV/premiere.utf16le.csv'],
['tests/data/Reader/CSV/premiere.utf16lebom.csv'],
['tests/data/Reader/CSV/premiere.utf32be.csv'],
['tests/data/Reader/CSV/premiere.utf32bebom.csv'],
['tests/data/Reader/CSV/premiere.utf32le.csv'],
['tests/data/Reader/CSV/premiere.utf32lebom.csv'],
['tests/data/Reader/CSV/premiere.win1252.csv'],
];
}
public function testGuessEncodingDefltIso2(): void
{
$filename = 'tests/data/Reader/CSV/premiere.win1252.csv';
$reader = new Csv();
$reader->setInputEncoding(Csv::guessEncoding($filename, 'ISO-8859-2'));
$spreadsheet = $reader->load($filename);
$sheet = $spreadsheet->getActiveSheet();
self::assertEquals('premičre', $sheet->getCell('A1')->getValue());
self::assertEquals('sixičme', $sheet->getCell('C2')->getValue());
}
public function testFallbackEncodingDefltIso2(): void
{
$filename = 'tests/data/Reader/CSV/premiere.win1252.csv';
$reader = new Csv();
self::assertSame('CP1252', $reader->getFallbackEncoding());
$reader->setInputEncoding(Csv::GUESS_ENCODING);
$reader->setFallbackEncoding('ISO-8859-2');
$spreadsheet = $reader->load($filename);
$sheet = $spreadsheet->getActiveSheet();
self::assertEquals('premičre', $sheet->getCell('A1')->getValue());
self::assertEquals('sixičme', $sheet->getCell('C2')->getValue());
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Gnumeric/GnumericStylesTest.php | tests/PhpSpreadsheetTests/Reader/Gnumeric/GnumericStylesTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Gnumeric;
use PhpOffice\PhpSpreadsheet\Cell\DataType;
use PhpOffice\PhpSpreadsheet\Reader\Gnumeric;
use PhpOffice\PhpSpreadsheet\Style\Alignment;
use PhpOffice\PhpSpreadsheet\Style\Border;
use PhpOffice\PhpSpreadsheet\Style\Fill;
use PhpOffice\PhpSpreadsheet\Style\Font;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class GnumericStylesTest extends TestCase
{
#[DataProvider('providerBorderStyle')]
public function testBorderStyle(string $style, string $expectedResult): void
{
$styles = Gnumeric::gnumericMappings();
/** @var string[] */
$borders = $styles['borderStyle'];
self::assertEquals($expectedResult, $borders[$style]);
}
public function testBorderStyleCoverage(): void
{
$styles = Gnumeric::gnumericMappings();
/** @var mixed[] */
$expected = $styles['borderStyle'];
$covered = [];
foreach ($expected as $key => $val) {
$covered[$key] = 0;
}
$tests = $this->providerBorderStyle();
foreach ($tests as $test) {
$covered[$test[0]] = 1;
}
foreach ($covered as $key => $val) {
self::assertEquals(1, $val, "Borderstyle $key not tested");
}
}
#[DataProvider('providerfillType')]
public function testFillType(string $style, string $expectedResult): void
{
$styles = Gnumeric::gnumericMappings();
/** @var string[] */
$borders = $styles['fillType'];
self::assertEquals($expectedResult, $borders[$style]);
}
public function testFillTypeCoverage(): void
{
$styles = Gnumeric::gnumericMappings();
/** @var mixed[] */
$expected = $styles['fillType'];
$covered = [];
foreach ($expected as $key => $val) {
$covered[$key] = 0;
}
$tests = $this->providerfillType();
foreach ($tests as $test) {
$covered[$test[0]] = 1;
}
foreach ($covered as $key => $val) {
self::assertEquals(1, $val, "fillType $key not tested");
}
}
#[DataProvider('providerHorizontal')]
public function testHorizontal(string $style, string $expectedResult): void
{
$styles = Gnumeric::gnumericMappings();
/** @var string[] */
$borders = $styles['horizontal'];
self::assertEquals($expectedResult, $borders[$style]);
}
public function testHorizontalCoverage(): void
{
$styles = Gnumeric::gnumericMappings();
/** @var mixed[] */
$expected = $styles['horizontal'];
$covered = [];
foreach ($expected as $key => $val) {
$covered[$key] = 0;
}
$tests = $this->providerHorizontal();
foreach ($tests as $test) {
$covered[$test[0]] = 1;
}
foreach ($covered as $key => $val) {
self::assertEquals(1, $val, "horizontal $key not tested");
}
}
#[DataProvider('providerunderline')]
public function testUnderline(string $style, string $expectedResult): void
{
$styles = Gnumeric::gnumericMappings();
/** @var string[] */
$borders = $styles['underline'];
self::assertEquals($expectedResult, $borders[$style]);
}
public function testUnderlineCoverage(): void
{
$styles = Gnumeric::gnumericMappings();
/** @var mixed[] */
$expected = $styles['underline'];
/** @var int[] $covered */
$covered = [];
foreach ($expected as $key => $val) {
$covered[$key] = 0;
}
$tests = $this->providerUnderline();
foreach ($tests as $test) {
$covered[$test[0]] = 1;
}
foreach ($covered as $key => $val) {
self::assertEquals(1, $val, "underline $key not tested");
}
}
#[DataProvider('providerVertical')]
public function testVertical(string $style, string $expectedResult): void
{
$styles = Gnumeric::gnumericMappings();
/** @var mixed[] */
$borders = $styles['vertical'];
self::assertEquals($expectedResult, $borders[$style]);
}
public function testVerticalCoverage(): void
{
$styles = Gnumeric::gnumericMappings();
/** @var mixed[] */
$expected = $styles['vertical'];
$covered = [];
foreach ($expected as $key => $val) {
$covered[$key] = 0;
}
/** @var int[][] */
$tests = $this->providerVertical();
foreach ($tests as $test) {
$covered[$test[0]] = 1;
}
foreach ($covered as $key => $val) {
self::assertEquals(1, $val, "vertical $key not tested");
}
}
#[DataProvider('providerDataType')]
public function testDataType(string $style, string $expectedResult): void
{
$styles = Gnumeric::gnumericMappings();
/** @var string[] */
$borders = $styles['dataType'];
self::assertEquals($expectedResult, $borders[$style]);
}
public function testDataTypeCoverage(): void
{
$styles = Gnumeric::gnumericMappings();
/** @var mixed[] */
$expected = $styles['dataType'];
self::assertArrayNotHasKey('70', $expected);
self::assertArrayNotHasKey('80', $expected);
$covered = [];
foreach ($expected as $key => $val) {
$covered[$key] = 0;
}
/** @var int[][] */
$tests = $this->providerDataType();
foreach ($tests as $test) {
$covered[$test[0]] = 1;
}
foreach ($covered as $key => $val) {
self::assertEquals(1, $val, "dataType $key not tested");
}
}
/** @return array<int, array{0: string, 1:string}> */
public static function providerBorderStyle(): array
{
return [
['0', Border::BORDER_NONE],
['1', Border::BORDER_THIN],
['2', Border::BORDER_MEDIUM],
['3', Border::BORDER_SLANTDASHDOT],
['4', Border::BORDER_DASHED],
['5', Border::BORDER_THICK],
['6', Border::BORDER_DOUBLE],
['7', Border::BORDER_DOTTED],
['8', Border::BORDER_MEDIUMDASHED],
['9', Border::BORDER_DASHDOT],
['10', Border::BORDER_MEDIUMDASHDOT],
['11', Border::BORDER_DASHDOTDOT],
['12', Border::BORDER_MEDIUMDASHDOTDOT],
['13', Border::BORDER_MEDIUMDASHDOTDOT],
];
}
/** @return array<int, array{0: string, 1:string}> */
public static function providerFillType(): array
{
return [
['1', Fill::FILL_SOLID],
['2', Fill::FILL_PATTERN_DARKGRAY],
['3', Fill::FILL_PATTERN_MEDIUMGRAY],
['4', Fill::FILL_PATTERN_LIGHTGRAY],
['5', Fill::FILL_PATTERN_GRAY125],
['6', Fill::FILL_PATTERN_GRAY0625],
['7', Fill::FILL_PATTERN_DARKHORIZONTAL],
['8', Fill::FILL_PATTERN_DARKVERTICAL],
['9', Fill::FILL_PATTERN_DARKDOWN],
['10', Fill::FILL_PATTERN_DARKUP],
['11', Fill::FILL_PATTERN_DARKGRID],
['12', Fill::FILL_PATTERN_DARKTRELLIS],
['13', Fill::FILL_PATTERN_LIGHTHORIZONTAL],
['14', Fill::FILL_PATTERN_LIGHTVERTICAL],
['15', Fill::FILL_PATTERN_LIGHTUP],
['16', Fill::FILL_PATTERN_LIGHTDOWN],
['17', Fill::FILL_PATTERN_LIGHTGRID],
['18', Fill::FILL_PATTERN_LIGHTTRELLIS],
];
}
/** @return array<int, array{0: string, 1:string}> */
public static function providerHorizontal(): array
{
return [
['1', Alignment::HORIZONTAL_GENERAL],
['2', Alignment::HORIZONTAL_LEFT],
['4', Alignment::HORIZONTAL_RIGHT],
['8', Alignment::HORIZONTAL_CENTER],
['16', Alignment::HORIZONTAL_CENTER_CONTINUOUS],
['32', Alignment::HORIZONTAL_JUSTIFY],
['64', Alignment::HORIZONTAL_CENTER_CONTINUOUS],
];
}
/** @return array<int, array{0: string, 1:string}> */
public static function providerUnderline(): array
{
return [
['1', Font::UNDERLINE_SINGLE],
['2', Font::UNDERLINE_DOUBLE],
['3', Font::UNDERLINE_SINGLEACCOUNTING],
['4', Font::UNDERLINE_DOUBLEACCOUNTING],
];
}
public static function providerVertical(): array
{
return [
['1', Alignment::VERTICAL_TOP],
['2', Alignment::VERTICAL_BOTTOM],
['4', Alignment::VERTICAL_CENTER],
['8', Alignment::VERTICAL_JUSTIFY],
];
}
public static function providerDataType(): array
{
return [
['10', DataType::TYPE_NULL],
['20', DataType::TYPE_BOOL],
['30', DataType::TYPE_NUMERIC], // Integer doesn't exist in Excel
['40', DataType::TYPE_NUMERIC], // Float
['50', DataType::TYPE_ERROR],
['60', DataType::TYPE_STRING],
//'70': // Cell Range
//'80': // Array
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Gnumeric/ArrayFormulaTest.php | tests/PhpSpreadsheetTests/Reader/Gnumeric/ArrayFormulaTest.php | <?php
namespace PhpOffice\PhpSpreadsheetTests\Reader\Gnumeric;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Cell\DataType;
use PhpOffice\PhpSpreadsheet\Reader\Gnumeric;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class ArrayFormulaTest extends TestCase
{
/** @param float|mixed[] $expectedValue */
#[DataProvider('arrayFormulaReaderProvider')]
public function testArrayFormulaReader(
string $cellAddress,
string $expectedRange,
string $expectedFormula,
array|float $expectedValue
): void {
$filename = 'tests/data/Reader/Gnumeric/ArrayFormulaTest.gnumeric';
$reader = new Gnumeric();
$spreadsheet = $reader->load($filename);
$worksheet = $spreadsheet->getActiveSheet();
$cell = $worksheet->getCell($cellAddress);
self::assertSame(DataType::TYPE_FORMULA, $cell->getDataType());
if (is_array($expectedValue)) {
self::assertSame(['t' => 'array', 'ref' => $expectedRange], $cell->getFormulaAttributes());
} else {
self::assertEmpty($cell->getFormulaAttributes());
}
self::assertSame($expectedFormula, strtoupper($cell->getValueString()));
Calculation::getInstance($spreadsheet)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY);
$worksheet->calculateArrays();
$cell = $worksheet->getCell($cellAddress);
self::assertSame($expectedValue, $cell->getCalculatedValue());
if (is_array($expectedValue)) {
self::assertSame($expectedValue, $worksheet->rangeToArray($expectedRange, formatData: false, reduceArrays: true));
} else {
self::assertSame([[$expectedValue]], $worksheet->rangeToArray($expectedRange, formatData: false, reduceArrays: true));
}
$spreadsheet->disconnectWorksheets();
}
public static function arrayFormulaReaderProvider(): array
{
return [
[
'D1',
'D1:E2',
'=A1:B1*A1:A2',
[[4, 6], [8, 12]],
],
[
'G1',
'G1:J1',
'=SIN({-1,0,1,2})',
[[-0.8414709848078965, 0.0, 0.8414709848078965, 0.9092974268256817]],
],
[
'G3',
'G3:G3',
'=MAX(SIN({-1,0,1,2}))',
0.9092974268256817,
],
[
'D4',
'D4:E5',
'=A4:B4*A4:A5',
[[9, 12], [15, 20]],
],
[
'D7',
'D7:E8',
'=A7:B7*A7:A8',
[[16, 20], [24, 30]],
],
[
'D10',
'D10:E11',
'=A10:B10*A10:A11',
[[25, 30], [35, 42]],
],
[
'D13',
'D13:E14',
'=A13:B13*A13:A14',
[[36, 42], [48, 56]],
],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Gnumeric/PageSetupTest.php | tests/PhpSpreadsheetTests/Reader/Gnumeric/PageSetupTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Gnumeric;
use PhpOffice\PhpSpreadsheet\Reader\Gnumeric;
use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup;
use PHPUnit\Framework\TestCase;
class PageSetupTest extends TestCase
{
private const MARGIN_PRECISION = 0.001;
public static function fileProvider(): array
{
return [
['tests/data/Reader/Gnumeric/PageSetup.gnumeric'],
['tests/data/Reader/Gnumeric/PageSetup.gnumeric.unzipped.xml'],
];
}
#[\PHPUnit\Framework\Attributes\DataProvider('fileProvider')]
public function testPageSetup(string $filename): void
{
$reader = new Gnumeric();
$spreadsheet = $reader->load($filename);
$assertions = $this->pageSetupAssertions();
$sheetCount = 0;
foreach ($spreadsheet->getAllSheets() as $worksheet) {
if (!array_key_exists($worksheet->getTitle(), $assertions)) {
self::fail('Unexpected worksheet ' . $worksheet->getTitle());
}
++$sheetCount;
$sheetAssertions = $assertions[$worksheet->getTitle()];
foreach ($sheetAssertions as $test => $expectedResult) {
$testMethodName = 'get' . ucfirst($test);
$actualResult = $worksheet->getPageSetup()->$testMethodName();
self::assertSame(
$expectedResult,
$actualResult,
"Failed assertion for Worksheet '{$worksheet->getTitle()}' {$test}"
);
}
}
self::assertCount($sheetCount, $assertions);
$spreadsheet->disconnectWorksheets();
}
#[\PHPUnit\Framework\Attributes\DataProvider('fileProvider')]
public function testPageMargins(string $filename): void
{
$reader = new Gnumeric();
$spreadsheet = $reader->load($filename);
$assertions = $this->pageMarginAssertions();
$sheetCount = 0;
foreach ($spreadsheet->getAllSheets() as $worksheet) {
if (!array_key_exists($worksheet->getTitle(), $assertions)) {
self::fail('Unexpected worksheet ' . $worksheet->getTitle());
}
++$sheetCount;
$sheetAssertions = $assertions[$worksheet->getTitle()];
foreach ($sheetAssertions as $test => $expectedResult) {
$testMethodName = 'get' . ucfirst($test);
$actualResult = $worksheet->getPageMargins()->$testMethodName();
self::assertEqualsWithDelta(
$expectedResult,
$actualResult,
self::MARGIN_PRECISION,
"Failed assertion for Worksheet '{$worksheet->getTitle()}' {$test} margin"
);
}
}
self::assertCount($sheetCount, $assertions);
$spreadsheet->disconnectWorksheets();
}
/** @return array<string, mixed[]> */
private function pageSetupAssertions(): array
{
return [
'Sheet1' => [
'orientation' => PageSetup::ORIENTATION_PORTRAIT,
'scale' => 75,
'horizontalCentered' => true,
'verticalCentered' => false,
'pageOrder' => PageSetup::PAGEORDER_DOWN_THEN_OVER,
],
'Sheet2' => [
'orientation' => PageSetup::ORIENTATION_LANDSCAPE,
'scale' => 100,
'horizontalCentered' => false,
'verticalCentered' => true,
'pageOrder' => PageSetup::PAGEORDER_OVER_THEN_DOWN,
],
'Sheet3' => [
'orientation' => PageSetup::ORIENTATION_PORTRAIT,
'scale' => 90,
'horizontalCentered' => true,
'verticalCentered' => true,
'pageOrder' => PageSetup::PAGEORDER_DOWN_THEN_OVER,
],
'Sheet4' => [
// Default Settings
'orientation' => PageSetup::ORIENTATION_PORTRAIT,
'scale' => 100,
'horizontalCentered' => false,
'verticalCentered' => false,
'pageOrder' => PageSetup::PAGEORDER_DOWN_THEN_OVER,
],
];
}
/** @return array<string, float[]> */
private function pageMarginAssertions(): array
{
return [
'Sheet1' => [
// Here the values are in inches
'top' => 0.315,
'header' => 0.630,
'left' => 0.512,
'right' => 0.512,
'bottom' => 0.315,
'footer' => 0.433,
],
'Sheet2' => [
// Here the values are in inches
'top' => 0.315,
'header' => 0.433,
'left' => 0.709,
'right' => 0.709,
'bottom' => 0.315,
'footer' => 0.433,
],
'Sheet3' => [
// Here the values are in inches
'top' => 0.512,
'header' => 0.433,
'left' => 0.709,
'right' => 0.709,
'bottom' => 0.512,
'footer' => 0.433,
],
'Sheet4' => [
// Default Settings (in inches)
'top' => 0.3,
'header' => 0.45,
'left' => 0.7,
'right' => 0.7,
'bottom' => 0.3,
'footer' => 0.45,
],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Gnumeric/GnumericFilter.php | tests/PhpSpreadsheetTests/Reader/Gnumeric/GnumericFilter.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Gnumeric;
use PhpOffice\PhpSpreadsheet\Reader\IReadFilter;
/** Define a Read Filter class implementing IReadFilter */
class GnumericFilter implements IReadFilter
{
public function readCell(string $columnAddress, int $row, string $worksheetName = ''): bool
{
return $row !== 4;
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Gnumeric/ArrayFormula2Test.php | tests/PhpSpreadsheetTests/Reader/Gnumeric/ArrayFormula2Test.php | <?php
namespace PhpOffice\PhpSpreadsheetTests\Reader\Gnumeric;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Cell\DataType;
use PhpOffice\PhpSpreadsheet\Reader\Gnumeric;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class ArrayFormula2Test extends TestCase
{
/** @param mixed[] $expectedValue */
#[DataProvider('arrayFormulaReaderProvider')]
public function testArrayFormulaReader(
string $cellAddress,
string $expectedRange,
string $expectedFormula,
array $expectedValue
): void {
$filename = 'tests/data/Reader/Gnumeric/ArrayFormulaTest2.gnumeric';
$reader = new Gnumeric();
$spreadsheet = $reader->load($filename);
$worksheet = $spreadsheet->getActiveSheet();
$cell = $worksheet->getCell($cellAddress);
self::assertSame(DataType::TYPE_FORMULA, $cell->getDataType());
self::assertSame(['t' => 'array', 'ref' => $expectedRange], $cell->getFormulaAttributes());
self::assertSame($expectedFormula, strtoupper($cell->getValueString()));
Calculation::getInstance($spreadsheet)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY);
$worksheet->calculateArrays();
$cell = $worksheet->getCell($cellAddress);
self::assertSame($expectedValue, $cell->getCalculatedValue());
self::assertSame($expectedValue, $worksheet->rangeToArray($expectedRange, formatData: false, reduceArrays: true));
$spreadsheet->disconnectWorksheets();
}
public static function arrayFormulaReaderProvider(): array
{
return [
[
'D1',
'D1:E2',
'=MMULT(A1:B2,A4:B5)',
[[21, 26], [37, 46]],
],
[
'G1',
'G1:J1',
'=SIN({-1,0,1,2})',
[[-0.8414709848078965, 0.0, 0.8414709848078965, 0.9092974268256817]],
],
[
'D4',
'D4:E5',
'=MMULT(A7:B8,A10:B11)',
[[55, 64], [79, 92]],
],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Gnumeric/HiddenWorksheetTest.php | tests/PhpSpreadsheetTests/Reader/Gnumeric/HiddenWorksheetTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Gnumeric;
use PhpOffice\PhpSpreadsheet\Reader\Gnumeric;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
use PHPUnit\Framework\TestCase;
class HiddenWorksheetTest extends TestCase
{
public function testPageSetup(): void
{
$filename = 'tests/data/Reader/Gnumeric/HiddenSheet.gnumeric';
$reader = new Gnumeric();
$spreadsheet = $reader->load($filename);
$assertions = $this->worksheetAssertions();
$sheetCount = 0;
foreach ($spreadsheet->getAllSheets() as $worksheet) {
if (!array_key_exists($worksheet->getTitle(), $assertions)) {
self::fail('Unexpected worksheet ' . $worksheet->getTitle());
}
++$sheetCount;
$sheetAssertions = $assertions[$worksheet->getTitle()];
foreach ($sheetAssertions as $test => $expectedResult) {
$actualResult = $worksheet->getSheetState();
self::assertSame(
$expectedResult,
$actualResult,
"Failed asserting sheet state {$expectedResult} for Worksheet '{$worksheet->getTitle()}' {$test}"
);
}
}
self::assertCount($sheetCount, $assertions);
$spreadsheet->disconnectWorksheets();
}
/** @return array<string, string[]> */
private function worksheetAssertions(): array
{
return [
'Sheet1' => [
'sheetState' => Worksheet::SHEETSTATE_VISIBLE,
],
'Sheet2' => [
'sheetState' => Worksheet::SHEETSTATE_HIDDEN,
],
];
}
public function testListWorksheetInfo(): void
{
$filename = 'tests/data/Reader/Gnumeric/HiddenSheet.gnumeric';
$reader = new Gnumeric();
$expected = [
[
'worksheetName' => 'Sheet1',
'lastColumnLetter' => 'A',
'lastColumnIndex' => 0,
'totalRows' => 1,
'totalColumns' => 1,
'sheetState' => 'visible',
],
[
'worksheetName' => 'Sheet2',
'lastColumnLetter' => 'A',
'lastColumnIndex' => 0,
'totalRows' => 1,
'totalColumns' => 1,
'sheetState' => 'hidden',
],
];
self::assertSame($expected, $reader->listWorksheetInfo($filename));
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Gnumeric/GnumericLoadTest.php | tests/PhpSpreadsheetTests/Reader/Gnumeric/GnumericLoadTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Gnumeric;
use DateTimeZone;
use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException;
use PhpOffice\PhpSpreadsheet\Reader\Exception as ReaderException;
use PhpOffice\PhpSpreadsheet\Reader\Gnumeric;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use PhpOffice\PhpSpreadsheet\Style\Border;
use PhpOffice\PhpSpreadsheet\Style\Borders;
use PhpOffice\PhpSpreadsheet\Style\Color;
use PhpOffice\PhpSpreadsheet\Style\Fill;
use PhpOffice\PhpSpreadsheet\Style\Font;
use PHPUnit\Framework\TestCase;
class GnumericLoadTest extends TestCase
{
public function testLoad(): void
{
$filename = 'samples/templates/GnumericTest.gnumeric';
$reader = new Gnumeric();
$spreadsheet = $reader->load($filename);
self::assertEquals(2, $spreadsheet->getSheetCount());
$sheet = $spreadsheet->getSheet(1);
self::assertEquals('Report Data', $sheet->getTitle());
self::assertEquals('BCD', $sheet->getCell('A4')->getValue());
$props = $spreadsheet->getProperties();
self::assertEquals('Mark Baker', $props->getCreator());
$creationDate = $props->getCreated();
$result = Date::formattedDateTimeFromTimestamp("$creationDate", 'Y-m-d\TH:i:s\Z', new DateTimeZone('UTC'));
self::assertEquals('2010-09-02T20:48:39Z', $result);
$creationDate = $props->getModified();
$result = Date::formattedDateTimeFromTimestamp("$creationDate", 'Y-m-d\TH:i:s\Z', new DateTimeZone('UTC'));
self::assertEquals('2020-06-05T05:15:21Z', $result);
$sheet = $spreadsheet->getSheet(0);
self::assertEquals('Sample Data', $sheet->getTitle());
self::assertEquals('Test String 1', $sheet->getCell('A1')->getValue());
self::assertEquals('FFFF0000', $sheet->getCell('A1')->getStyle()->getFont()->getColor()->getARGB());
self::assertEquals(Font::UNDERLINE_SINGLE, $sheet->getCell('A3')->getStyle()->getFont()->getUnderline());
self::assertEquals('Test with (") in string', $sheet->getCell('A4')->getValue());
self::assertEquals(22269, $sheet->getCell('A10')->getValue());
self::assertEquals('dd/mm/yyyy', $sheet->getCell('A10')->getStyle()->getNumberFormat()->getFormatCode());
self::assertEquals('19/12/1960', $sheet->getCell('A10')->getFormattedValue());
self::assertEquals(1.5, $sheet->getCell('A11')->getValue());
self::assertEquals('# ?0/??0', $sheet->getCell('A11')->getStyle()->getNumberFormat()->getFormatCode());
// Same pattern, same value, different display in Gnumeric vs Excel
//self::assertEquals('1 1/2', $sheet->getCell('A11')->getFormattedValue());
self::assertEquals('=B1+C1', $sheet->getCell('H1')->getValue());
self::assertEquals('=E2&F2', $sheet->getCell('J2')->getValue());
self::assertEquals('=sum(C1:C4)', $sheet->getCell('I5')->getValue());
self::assertTrue($sheet->getCell('E1')->getStyle()->getFont()->getBold());
self::assertTrue($sheet->getCell('E1')->getStyle()->getFont()->getItalic());
self::assertFalse($sheet->getCell('E2')->getStyle()->getFont()->getBold());
self::assertFalse($sheet->getCell('E2')->getStyle()->getFont()->getItalic());
self::assertEquals(Font::UNDERLINE_NONE, $sheet->getCell('E2')->getStyle()->getFont()->getUnderline());
self::assertTrue($sheet->getCell('E3')->getStyle()->getFont()->getBold());
self::assertFalse($sheet->getCell('E3')->getStyle()->getFont()->getItalic());
self::assertEquals(Font::UNDERLINE_NONE, $sheet->getCell('E3')->getStyle()->getFont()->getUnderline());
self::assertFalse($sheet->getCell('E4')->getStyle()->getFont()->getBold());
self::assertTrue($sheet->getCell('E4')->getStyle()->getFont()->getItalic());
self::assertEquals(Font::UNDERLINE_NONE, $sheet->getCell('E4')->getStyle()->getFont()->getUnderline());
self::assertTrue($sheet->getCell('F1')->getStyle()->getFont()->getBold());
self::assertFalse($sheet->getCell('F1')->getStyle()->getFont()->getItalic());
self::assertEquals(Font::UNDERLINE_NONE, $sheet->getCell('F1')->getStyle()->getFont()->getUnderline());
self::assertFalse($sheet->getCell('F2')->getStyle()->getFont()->getBold());
self::assertFalse($sheet->getCell('F2')->getStyle()->getFont()->getItalic());
self::assertEquals(Font::UNDERLINE_NONE, $sheet->getCell('F2')->getStyle()->getFont()->getUnderline());
self::assertTrue($sheet->getCell('F3')->getStyle()->getFont()->getBold());
self::assertTrue($sheet->getCell('F3')->getStyle()->getFont()->getItalic());
self::assertEquals(Font::UNDERLINE_NONE, $sheet->getCell('F3')->getStyle()->getFont()->getUnderline());
self::assertFalse($sheet->getCell('F4')->getStyle()->getFont()->getBold());
self::assertFalse($sheet->getCell('F4')->getStyle()->getFont()->getItalic());
self::assertEquals(Font::UNDERLINE_NONE, $sheet->getCell('F4')->getStyle()->getFont()->getUnderline());
self::assertEquals(Border::BORDER_MEDIUM, $sheet->getCell('C10')->getStyle()->getBorders()->getTop()->getBorderStyle());
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C10')->getStyle()->getBorders()->getRight()->getBorderStyle());
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C10')->getStyle()->getBorders()->getBottom()->getBorderStyle());
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C10')->getStyle()->getBorders()->getLeft()->getBorderStyle());
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C12')->getStyle()->getBorders()->getTop()->getBorderStyle());
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C12')->getStyle()->getBorders()->getRight()->getBorderStyle());
self::assertEquals(Border::BORDER_MEDIUM, $sheet->getCell('C12')->getStyle()->getBorders()->getBottom()->getBorderStyle());
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C12')->getStyle()->getBorders()->getLeft()->getBorderStyle());
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C14')->getStyle()->getBorders()->getTop()->getBorderStyle());
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C14')->getStyle()->getBorders()->getRight()->getBorderStyle());
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C14')->getStyle()->getBorders()->getBottom()->getBorderStyle());
self::assertEquals(Border::BORDER_MEDIUM, $sheet->getCell('C14')->getStyle()->getBorders()->getLeft()->getBorderStyle());
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C16')->getStyle()->getBorders()->getTop()->getBorderStyle());
self::assertEquals(Border::BORDER_MEDIUM, $sheet->getCell('C16')->getStyle()->getBorders()->getRight()->getBorderStyle());
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C16')->getStyle()->getBorders()->getBottom()->getBorderStyle());
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C16')->getStyle()->getBorders()->getLeft()->getBorderStyle());
self::assertEquals(Border::BORDER_THICK, $sheet->getCell('C18')->getStyle()->getBorders()->getTop()->getBorderStyle());
self::assertEquals(Color::COLOR_RED, $sheet->getCell('C18')->getStyle()->getBorders()->getTop()->getColor()->getARGB());
self::assertEquals(Border::BORDER_THICK, $sheet->getCell('C18')->getStyle()->getBorders()->getRight()->getBorderStyle());
self::assertEquals(Color::COLOR_YELLOW, $sheet->getCell('C18')->getStyle()->getBorders()->getRight()->getColor()->getARGB());
self::assertEquals(Border::BORDER_THICK, $sheet->getCell('C18')->getStyle()->getBorders()->getRight()->getBorderStyle());
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C18')->getStyle()->getBorders()->getBottom()->getBorderStyle());
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C18')->getStyle()->getBorders()->getLeft()->getBorderStyle());
self::assertEquals(Fill::FILL_PATTERN_DARKHORIZONTAL, $sheet->getCell('K19')->getStyle()->getFill()->getFillType());
self::assertEquals('FF00CCFF', $sheet->getCell('K19')->getStyle()->getFill()->getEndColor()->getARGB());
self::assertEquals(Color::COLOR_BLUE, $sheet->getCell('K19')->getStyle()->getFill()->getStartColor()->getARGB());
self::assertEquals(Fill::FILL_PATTERN_GRAY0625, $sheet->getCell('L19')->getStyle()->getFill()->getFillType());
self::assertEquals(Color::COLOR_RED, $sheet->getCell('L19')->getStyle()->getFill()->getEndColor()->getARGB());
self::assertEquals(Color::COLOR_YELLOW, $sheet->getCell('L19')->getStyle()->getFill()->getStartColor()->getARGB());
self::assertEquals(Fill::FILL_SOLID, $sheet->getCell('K3')->getStyle()->getFill()->getFillType());
self::assertEquals(Color::COLOR_RED, $sheet->getCell('K3')->getStyle()->getFill()->getStartColor()->getARGB());
self::assertEquals(45, $sheet->getCell('E22')->getStyle()->getAlignment()->getTextRotation());
self::assertEquals(-90, $sheet->getCell('G22')->getStyle()->getAlignment()->getTextRotation());
self::assertEquals(Border::BORDER_DOUBLE, $sheet->getCell('N13')->getStyle()->getBorders()->getBottom()->getBorderStyle());
self::assertEquals(Borders::DIAGONAL_BOTH, $sheet->getCell('E18')->getStyle()->getBorders()->getDiagonalDirection());
self::assertEquals(Borders::DIAGONAL_DOWN, $sheet->getCell('I18')->getStyle()->getBorders()->getDiagonalDirection());
self::assertEquals(Borders::DIAGONAL_UP, $sheet->getCell('J18')->getStyle()->getBorders()->getDiagonalDirection());
self::assertEquals(Font::UNDERLINE_DOUBLE, $sheet->getCell('A24')->getStyle()->getFont()->getUnderline());
self::assertTrue($sheet->getCell('B23')->getStyle()->getFont()->getSubScript());
self::assertTrue($sheet->getCell('B24')->getStyle()->getFont()->getSuperScript());
$rowDimension = $sheet->getRowDimension(30);
self::assertFalse($rowDimension->getVisible());
self::assertSame('B24', $sheet->getSelectedCells());
$spreadsheet->disconnectWorksheets();
}
public function testLoadFilter(): void
{
$filename = 'samples/templates/GnumericTest.gnumeric';
$reader = new Gnumeric();
$filter = new GnumericFilter();
$reader->setReadFilter($filter);
$spreadsheet = $reader->load($filename);
self::assertEquals(2, $spreadsheet->getSheetCount());
$sheet = $spreadsheet->getSheet(1);
self::assertEquals('Report Data', $sheet->getTitle());
self::assertEquals('', $sheet->getCell('A4')->getValue());
$props = $spreadsheet->getProperties();
self::assertEquals('Mark Baker', $props->getCreator());
$spreadsheet->disconnectWorksheets();
}
public function testLoadOld(): void
{
$filename = 'samples/templates/old.gnumeric';
$reader = new Gnumeric();
$spreadsheet = $reader->load($filename);
$props = $spreadsheet->getProperties();
self::assertEquals('David Gilbert', $props->getCreator());
$spreadsheet->disconnectWorksheets();
}
public function testLoadSelectedSheets(): void
{
$filename = 'samples/templates/GnumericTest.gnumeric';
$reader = new Gnumeric();
$reader->setLoadSheetsOnly(['Unknown Sheet', 'Report Data']);
$spreadsheet = $reader->load($filename);
self::assertEquals(1, $spreadsheet->getSheetCount());
$sheet = $spreadsheet->getSheet(0);
self::assertEquals('Report Data', $sheet->getTitle());
self::assertEquals('Third Heading', $sheet->getCell('C2')->getValue());
self::assertSame('A1', $sheet->getSelectedCells());
$spreadsheet->disconnectWorksheets();
}
public function testLoadNoSelectedSheets(): void
{
$this->expectException(PhpSpreadsheetException::class);
$this->expectExceptionMessage('You tried to set a sheet active by the out of bounds index');
$filename = 'samples/templates/GnumericTest.gnumeric';
$reader = new Gnumeric();
$reader->setLoadSheetsOnly(['Unknown Sheet', 'xReport Data']);
$reader->load($filename);
}
public function testLoadNotGnumeric(): void
{
$this->expectException(ReaderException::class);
$this->expectExceptionMessage('invalid Gnumeric file');
$filename = 'samples/templates/excel2003.xml';
$reader = new Gnumeric();
$reader->load($filename);
}
public function testLoadNotXml(): void
{
$this->expectException(ReaderException::class);
$this->expectExceptionMessage('invalid Gnumeric file');
$filename = __FILE__;
$reader = new Gnumeric();
$reader->load($filename);
}
public function testDoctype(): void
{
$this->expectException(ReaderException::class);
$this->expectExceptionMessage('prevent XXE');
$filename = 'tests/data/Reader/Gnumeric/xmlwithdoctype.gnumeric';
$reader = new Gnumeric();
$reader->load($filename);
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Gnumeric/DefinedNameTest.php | tests/PhpSpreadsheetTests/Reader/Gnumeric/DefinedNameTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Gnumeric;
use PhpOffice\PhpSpreadsheet\Reader\Gnumeric;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class DefinedNameTest extends TestCase
{
public static function fileProvider(): array
{
return [
['tests/data/Reader/Gnumeric/apostrophe3a.gnumeric', 'Sheet1'],
['tests/data/Reader/Gnumeric/apostrophe3b.gnumeric', 'Apo\'strophe'],
];
}
#[DataProvider('fileProvider')]
public function testDefinedName(string $filename, string $sheetName): void
{
$reader = new Gnumeric();
$spreadsheet = $reader->load($filename);
$sheet = $spreadsheet->getActiveSheet();
self::assertSame($sheetName, $sheet->getTitle());
self::assertSame('=sheet1first', $sheet->getCell('C1')->getValue());
self::assertSame(1, $sheet->getCell('C1')->getCalculatedValue());
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Gnumeric/GnumericInfoTest.php | tests/PhpSpreadsheetTests/Reader/Gnumeric/GnumericInfoTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Gnumeric;
use PhpOffice\PhpSpreadsheet\Reader\Exception as ReaderException;
use PhpOffice\PhpSpreadsheet\Reader\Gnumeric;
use PHPUnit\Framework\TestCase;
class GnumericInfoTest extends TestCase
{
public function testListNames(): void
{
$filename = 'samples/templates/GnumericTest.gnumeric';
$reader = new Gnumeric();
$names = $reader->listWorksheetNames($filename);
self::assertCount(2, $names);
self::assertEquals('Sample Data', $names[0]);
self::assertEquals('Report Data', $names[1]);
}
public function testListInfo(): void
{
$filename = 'samples/templates/GnumericTest.gnumeric';
$reader = new Gnumeric();
$info = $reader->listWorksheetInfo($filename);
$expected = [
[
'worksheetName' => 'Sample Data',
'lastColumnLetter' => 'N',
'lastColumnIndex' => 13,
'totalRows' => 31,
'totalColumns' => 14,
'sheetState' => 'visible',
],
[
'worksheetName' => 'Report Data',
'lastColumnLetter' => 'K',
'lastColumnIndex' => 10,
'totalRows' => 65535,
'totalColumns' => 11,
'sheetState' => 'visible',
],
];
self::assertEquals($expected, $info);
}
public function testListNamesNotGumeric(): void
{
$this->expectException(ReaderException::class);
$this->expectExceptionMessage('invalid Gnumeric file');
$filename = 'samples/templates/excel2003.xml';
$reader = new Gnumeric();
$reader->listWorksheetNames($filename);
}
public function testListInfoNotXml(): void
{
$this->expectException(ReaderException::class);
$this->expectExceptionMessage('invalid Gnumeric file');
$filename = __FILE__;
$reader = new Gnumeric();
$reader->listWorksheetInfo($filename);
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Gnumeric/AutoFilterTest.php | tests/PhpSpreadsheetTests/Reader/Gnumeric/AutoFilterTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Gnumeric;
use PhpOffice\PhpSpreadsheet\Reader\Gnumeric;
use PHPUnit\Framework\TestCase;
class AutoFilterTest extends TestCase
{
public function testAutoFilterRange(): void
{
$filename = 'tests/data/Reader/Gnumeric/Autofilter_Basic.gnumeric';
$reader = new Gnumeric();
$spreadsheet = $reader->load($filename);
$worksheet = $spreadsheet->getActiveSheet();
$autoFilterRange = $worksheet->getAutoFilter()->getRange();
self::assertSame('A1:D57', $autoFilterRange);
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Reader/Xlsx/Issue3464Test.php | tests/PhpSpreadsheetTests/Reader/Xlsx/Issue3464Test.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\RichText\RichText;
class Issue3464Test extends \PHPUnit\Framework\TestCase
{
private static string $testbook = 'tests/data/Reader/XLSX/issue.3464.xlsx';
public function testReadFontColor(): void
{
$inputFileType = IOFactory::identify(self::$testbook);
$objReader = IOFactory::createReader($inputFileType);
$objReader->setReadEmptyCells(false);
$spreadsheet = $objReader->load(self::$testbook);
$sheet = $spreadsheet->getActiveSheet();
$rickText = $sheet->getCell([1, 1])->getValue();
self::assertInstanceOf(RichText::class, $rickText);
$elements = $rickText->getRichTextElements();
self::assertCount(2, $elements);
self::assertEquals("产品介绍\n", $elements[0]->getText());
$font = $elements[0]->getFont();
self::assertNotNull($font);
self::assertEquals('7f7f7f', $font->getColor()->getRGB());
self::assertEquals('(这是一行示例数据,在导入时需要删除该行)', $elements[1]->getText());
$font = $elements[1]->getFont();
self::assertNotNull($font);
self::assertEquals('ff2600', $font->getColor()->getRGB());
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.