add support for STYLEREF field

This commit is contained in:
troosan 2018-04-17 07:34:57 +02:00
parent dd27f668e0
commit c52c96d657
4 changed files with 13 additions and 0 deletions

View File

@ -6,15 +6,20 @@ include_once 'Sample_Header.php';
// New Word document // New Word document
echo date('H:i:s'), ' Create new PhpWord object', EOL; echo date('H:i:s'), ' Create new PhpWord object', EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord(); $phpWord = new \PhpOffice\PhpWord\PhpWord();
PhpOffice\PhpWord\Style::addTitleStyle(1, array('size' => 14));
// New section // New section
$section = $phpWord->addSection(); $section = $phpWord->addSection();
$section->addTitle('This page demos fields');
// Add Field elements // Add Field elements
// See Element/Field.php for all options // See Element/Field.php for all options
$section->addText('Date field:'); $section->addText('Date field:');
$section->addField('DATE', array('dateformat' => 'dddd d MMMM yyyy H:mm:ss'), array('PreserveFormat')); $section->addField('DATE', array('dateformat' => 'dddd d MMMM yyyy H:mm:ss'), array('PreserveFormat'));
$section->addText('Style Ref field:');
$section->addField('STYLEREF', array('StyleIdentifier' => 'Heading 1'));
$section->addText('Page field:'); $section->addText('Page field:');
$section->addField('PAGE', array('format' => 'Arabic')); $section->addField('PAGE', array('format' => 'Arabic'));

View File

@ -78,6 +78,10 @@ class Field extends AbstractElement
'properties' => array(), 'properties' => array(),
'options' => array('PreserveFormat'), 'options' => array('PreserveFormat'),
), ),
'STYLEREF' => array(
'properties' => array('StyleIdentifier' => ''),
'options' => array('PreserveFormat'),
),
); );
/** /**

View File

@ -177,6 +177,9 @@ class Field extends Text
case 'macroname': case 'macroname':
$propertiesAndOptions .= $propval . ' '; $propertiesAndOptions .= $propval . ' ';
break; break;
default:
$propertiesAndOptions .= '"' . $propval . '" ';
break;
} }
} }

View File

@ -288,6 +288,7 @@ class ElementTest extends \PHPUnit\Framework\TestCase
$section->addField('DATE', array(), array('LunarCalendar')); $section->addField('DATE', array(), array('LunarCalendar'));
$section->addField('DATE', array(), array('SakaEraCalendar')); $section->addField('DATE', array(), array('SakaEraCalendar'));
$section->addField('NUMPAGES', array('format' => 'roman', 'numformat' => '0,00'), array('SakaEraCalendar')); $section->addField('NUMPAGES', array('format' => 'roman', 'numformat' => '0,00'), array('SakaEraCalendar'));
$section->addField('STYLEREF', array('StyleIdentifier' => 'Heading 1'));
$doc = TestHelperDOCX::getDocument($phpWord); $doc = TestHelperDOCX::getDocument($phpWord);
$element = '/w:document/w:body/w:p/w:r/w:instrText'; $element = '/w:document/w:body/w:p/w:r/w:instrText';