Skip to content

Commit c52c96d

Browse files
committed
add support for STYLEREF field
1 parent dd27f66 commit c52c96d

File tree

4 files changed

+13
-0
lines changed

4 files changed

+13
-0
lines changed

samples/Sample_27_Field.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,20 @@
66
// New Word document
77
echo date('H:i:s'), ' Create new PhpWord object', EOL;
88
$phpWord = new \PhpOffice\PhpWord\PhpWord();
9+
PhpOffice\PhpWord\Style::addTitleStyle(1, array('size' => 14));
910

1011
// New section
1112
$section = $phpWord->addSection();
13+
$section->addTitle('This page demos fields');
1214

1315
// Add Field elements
1416
// See Element/Field.php for all options
1517
$section->addText('Date field:');
1618
$section->addField('DATE', array('dateformat' => 'dddd d MMMM yyyy H:mm:ss'), array('PreserveFormat'));
1719

20+
$section->addText('Style Ref field:');
21+
$section->addField('STYLEREF', array('StyleIdentifier' => 'Heading 1'));
22+
1823
$section->addText('Page field:');
1924
$section->addField('PAGE', array('format' => 'Arabic'));
2025

src/PhpWord/Element/Field.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ class Field extends AbstractElement
7878
'properties' => array(),
7979
'options' => array('PreserveFormat'),
8080
),
81+
'STYLEREF' => array(
82+
'properties' => array('StyleIdentifier' => ''),
83+
'options' => array('PreserveFormat'),
84+
),
8185
);
8286

8387
/**

src/PhpWord/Writer/Word2007/Element/Field.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ private function buildPropertiesAndOptions(\PhpOffice\PhpWord\Element\Field $ele
177177
case 'macroname':
178178
$propertiesAndOptions .= $propval . ' ';
179179
break;
180+
default:
181+
$propertiesAndOptions .= '"' . $propval . '" ';
182+
break;
180183
}
181184
}
182185

tests/PhpWord/Writer/Word2007/ElementTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ public function testFieldElement()
288288
$section->addField('DATE', array(), array('LunarCalendar'));
289289
$section->addField('DATE', array(), array('SakaEraCalendar'));
290290
$section->addField('NUMPAGES', array('format' => 'roman', 'numformat' => '0,00'), array('SakaEraCalendar'));
291+
$section->addField('STYLEREF', array('StyleIdentifier' => 'Heading 1'));
291292
$doc = TestHelperDOCX::getDocument($phpWord);
292293

293294
$element = '/w:document/w:body/w:p/w:r/w:instrText';

0 commit comments

Comments
 (0)