Skip to content

Commit de9fdc3

Browse files
committed
XML Reader Recognize Indents
Fix #4448
1 parent e831636 commit de9fdc3

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed

src/PhpSpreadsheet/Reader/Xml/Style/Alignment.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ public function parseStyle(SimpleXMLElement $styleAttributes): array
4949
case 'Rotate':
5050
$style['alignment']['textRotation'] = $styleAttributeValue;
5151

52+
break;
53+
case 'Indent':
54+
$style['alignment']['indent'] = $styleAttributeValue;
55+
5256
break;
5357
}
5458
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xml;
6+
7+
use PhpOffice\PhpSpreadsheet\Reader\Xml;
8+
use PHPUnit\Framework\TestCase;
9+
10+
class Issue4448Test extends TestCase
11+
{
12+
private static string $testbook = 'tests/data/Reader/Xml/issue.4448.xml';
13+
14+
public function testIndent(): void
15+
{
16+
$reader = new Xml();
17+
$spreadsheet = $reader->load(self::$testbook);
18+
$sheet = $spreadsheet->getActiveSheet();
19+
self::assertSame(
20+
5,
21+
$sheet->getStyle('A2')
22+
->getAlignment()
23+
->getIndent()
24+
);
25+
self::assertSame(
26+
0,
27+
$sheet->getStyle('A1')
28+
->getAlignment()
29+
->getIndent()
30+
);
31+
$spreadsheet->disconnectWorksheets();
32+
}
33+
}

tests/data/Reader/Xml/issue.4448.xml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?xml version="1.0"?>
2+
<?mso-application progid="Excel.Sheet"?>
3+
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
4+
xmlns:o="urn:schemas-microsoft-com:office:office"
5+
xmlns:x="urn:schemas-microsoft-com:office:excel"
6+
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
7+
xmlns:html="http://www.w3.org/TR/REC-html40">
8+
<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
9+
<Author>owen</Author>
10+
<LastAuthor>owen</LastAuthor>
11+
<Created>2025-04-20T15:09:21Z</Created>
12+
<Version>16.00</Version>
13+
</DocumentProperties>
14+
<OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">
15+
<AllowPNG/>
16+
</OfficeDocumentSettings>
17+
<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
18+
<WindowHeight>6630</WindowHeight>
19+
<WindowWidth>19200</WindowWidth>
20+
<WindowTopX>32767</WindowTopX>
21+
<WindowTopY>32767</WindowTopY>
22+
<ProtectStructure>False</ProtectStructure>
23+
<ProtectWindows>False</ProtectWindows>
24+
</ExcelWorkbook>
25+
<Styles>
26+
<Style ss:ID="Default" ss:Name="Normal">
27+
<Alignment ss:Vertical="Bottom"/>
28+
<Borders/>
29+
<Font ss:FontName="Aptos Narrow" x:Family="Swiss" ss:Size="11"
30+
ss:Color="#000000"/>
31+
<Interior/>
32+
<NumberFormat/>
33+
<Protection/>
34+
</Style>
35+
<Style ss:ID="s63">
36+
<Alignment ss:Horizontal="Left" ss:Vertical="Bottom" ss:Indent="5"/>
37+
</Style>
38+
</Styles>
39+
<Worksheet ss:Name="Sheet1">
40+
<Table ss:ExpandedColumnCount="1" ss:ExpandedRowCount="3" x:FullColumns="1"
41+
x:FullRows="1" ss:DefaultRowHeight="14.5">
42+
<Row>
43+
<Cell><Data ss:Type="String">a</Data></Cell>
44+
</Row>
45+
<Row>
46+
<Cell ss:StyleID="s63"><Data ss:Type="String">b</Data></Cell>
47+
</Row>
48+
<Row>
49+
<Cell><Data ss:Type="String">c</Data></Cell>
50+
</Row>
51+
</Table>
52+
<WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
53+
<PageSetup>
54+
<Header x:Margin="0.3"/>
55+
<Footer x:Margin="0.3"/>
56+
<PageMargins x:Bottom="0.75" x:Left="0.7" x:Right="0.7" x:Top="0.75"/>
57+
</PageSetup>
58+
<Selected/>
59+
<Panes>
60+
<Pane>
61+
<Number>3</Number>
62+
<ActiveRow>1</ActiveRow>
63+
</Pane>
64+
</Panes>
65+
<ProtectObjects>False</ProtectObjects>
66+
<ProtectScenarios>False</ProtectScenarios>
67+
</WorksheetOptions>
68+
</Worksheet>
69+
</Workbook>

0 commit comments

Comments
 (0)