Skip to content

Commit 312b7a2

Browse files
authored
Merge pull request #365 from Progi1984/issue347
#347 : PowerPoint2007 Writer : Margins in table cell
2 parents 4a0adf8 + 97c0126 commit 312b7a2

File tree

5 files changed

+38
-20
lines changed

5 files changed

+38
-20
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## 0.9.0 - WIP
44

5+
### Bugfix
6+
- PowerPoint2007 Writer : Margins in table cell - @Progi1984 GH-347
7+
58
### Changes
69
- PowerPoint2007 Writer : Write percentage values with a trailing percent sign instead of formatted as 1000th of a percent to comply with the standard - @k42b3 GH-307
710

docs/shapes_table.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ You can access cell object directly.
5151
Define margins of a cell
5252
~~~~~~~~~~~~~~~~~~~~~~~~
5353
Margins of cells are defined by margins of the first paragraph of cell.
54+
Margins of cells are defined in pixels.
5455

5556
For defining margins of cell, you can use the `setMargin*` method of a Alignment object of the active paragraph of a Cell object.
5657

samples/Sample_04_Table.php

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,13 @@
6161
->setRotation(90)
6262
->setStartColor(new Color('FFE06B20'))
6363
->setEndColor(new Color('FFFFFFFF'));
64-
$row->nextCell()->createTextRun('R1C1')->getFont()->setBold(true);
65-
$row->getCell()->getActiveParagraph()->getAlignment()->setMarginLeft(20);
66-
$row->nextCell()->createTextRun('R1C2')->getFont()->setBold(true);
67-
$row->nextCell()->createTextRun('R1C3')->getFont()->setBold(true);
64+
$oCell = $row->nextCell();
65+
$oCell->createTextRun('R1C1')->getFont()->setBold(true);
66+
$oCell->getActiveParagraph()->getAlignment()->setMarginLeft(20);
67+
$oCell = $row->nextCell();
68+
$oCell->createTextRun('R1C2')->getFont()->setBold(true);
69+
$oCell = $row->nextCell();
70+
$oCell->createTextRun('R1C3')->getFont()->setBold(true);
6871

6972
foreach ($row->getCells() as $cell) {
7073
$cell->getBorders()->getTop()->setLineWidth(4)
@@ -78,23 +81,34 @@
7881
$row->getFill()->setFillType(Fill::FILL_SOLID)
7982
->setStartColor(new Color('FFE06B20'))
8083
->setEndColor(new Color('FFE06B20'));
81-
$row->nextCell()->createTextRun('R2C1');
82-
$row->getCell()->getActiveParagraph()->getAlignment()
84+
$oCell = $row->nextCell();
85+
$oCell->createTextRun('R2C1');
86+
$oCell->getActiveParagraph()->getAlignment()
8387
->setMarginLeft(30)
8488
->setTextDirection(\PhpOffice\PhpPresentation\Style\Alignment::TEXT_DIRECTION_VERTICAL_270);
85-
$row->nextCell()->createTextRun('R2C2');
86-
$row->nextCell()->createTextRun('R2C3');
89+
$oCell = $row->nextCell();
90+
$oCell->createTextRun('R2C2');
91+
$oCell->getActiveParagraph()->getAlignment()
92+
->setMarginBottom(10)
93+
->setMarginTop(20)
94+
->setMarginRight(30)
95+
->setMarginLeft(40);
96+
$oCell = $row->nextCell();
97+
$oCell->createTextRun('R2C3');
8798

8899
// Add row
89100
echo date('H:i:s') . ' Add row'.EOL;
90101
$row = $shape->createRow();
91102
$row->getFill()->setFillType(Fill::FILL_SOLID)
92103
->setStartColor(new Color('FFE06B20'))
93104
->setEndColor(new Color('FFE06B20'));
94-
$row->nextCell()->createTextRun('R3C1');
95-
$row->getCell()->getActiveParagraph()->getAlignment()->setMarginLeft(40);
96-
$row->nextCell()->createTextRun('R3C2');
97-
$row->nextCell()->createTextRun('R3C3');
105+
$oCell = $row->nextCell();
106+
$oCell->createTextRun('R3C1');
107+
$oCell->getActiveParagraph()->getAlignment()->setMarginLeft(40);
108+
$oCell = $row->nextCell();
109+
$oCell->createTextRun('R3C2');
110+
$oCell = $row->nextCell();
111+
$oCell->createTextRun('R3C3');
98112

99113
// Add row
100114
echo date('H:i:s') . ' Add row'.EOL;

src/PhpPresentation/Writer/PowerPoint2007/AbstractSlide.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -451,10 +451,10 @@ protected function writeShapeTable(XMLWriter $objWriter, ShapeTable $shape, $sha
451451
}
452452

453453
// Margins
454-
$objWriter->writeAttribute('marL', $firstParagraphAlignment->getMarginLeft());
455-
$objWriter->writeAttribute('marR', $firstParagraphAlignment->getMarginRight());
456-
$objWriter->writeAttribute('marT', $firstParagraphAlignment->getMarginTop());
457-
$objWriter->writeAttribute('marB', $firstParagraphAlignment->getMarginBottom());
454+
$objWriter->writeAttribute('marL', CommonDrawing::pixelsToEmu($firstParagraphAlignment->getMarginLeft()));
455+
$objWriter->writeAttribute('marR', CommonDrawing::pixelsToEmu($firstParagraphAlignment->getMarginRight()));
456+
$objWriter->writeAttribute('marT', CommonDrawing::pixelsToEmu($firstParagraphAlignment->getMarginTop()));
457+
$objWriter->writeAttribute('marB', CommonDrawing::pixelsToEmu($firstParagraphAlignment->getMarginBottom()));
458458

459459
// Determine borders
460460
$borderLeft = $currentCell->getBorders()->getLeft();

tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptSlidesTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -724,10 +724,10 @@ public function testTableWithCellMargin()
724724

725725
$element = '/p:sld/p:cSld/p:spTree/p:graphicFrame/a:graphic/a:graphicData/a:tbl/a:tr/a:tc/a:tcPr';
726726
$this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
727-
$this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'marB', 10);
728-
$this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'marL', 20);
729-
$this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'marR', 30);
730-
$this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'marT', 40);
727+
$this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'marB', Drawing::pixelsToEmu(10));
728+
$this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'marL', Drawing::pixelsToEmu(20));
729+
$this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'marR', Drawing::pixelsToEmu(30));
730+
$this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'marT', Drawing::pixelsToEmu(40));
731731
}
732732

733733
public function testTableWithColspan()

0 commit comments

Comments
 (0)