Skip to content

Conversation

@sos-productions
Copy link

Textbox fields name and value can be retrieved using this code:
$phpWord = \PhpOffice\PhpWord\IOFactory::load($docfile);

 $fields[]; $sections = $phpWord->getSections(); foreach ($sections as $key => $value) { $sectionElement = $value->getElements(); $first=true; foreach ($sectionElement as $elementKey => $elementValue) { if($elementValue instanceof \PhpOffice\PhpWord\Element\PreserveText) { $fieldDef=$elementValue->getText(); if(count($fieldDef)==2) { array_unshift($fieldDef,""); } /** * array (size=3) 0 => string '[1=Falun Dafa is Good]' 1 => string '{FORMTEXT}' 2 => string 'SayToTheWorldField=Falun Dafa est Bon' */ list($sos_orig_text,$DATATYPE,$sos_trad_text)= $fieldDef; if(trim($DATATYPE,'{ }')== 'FORMTEXT') { $field=explode('=',$sos_trad_text."=".trim($sos_orig_text,'[]')); $fields[]=$field; }else { var_dump($elementValue->getText()); var_dump("Unsupported field Type $DATATYPE :"); die("stop"); } } 

echo "

";
echo(htmlentities(implode("\n",$fields)));
echo "
";

Olivier added 3 commits December 17, 2019 10:43
Textbox fields name and value can be retrieved using this code: $phpWord = \PhpOffice\PhpWord\IOFactory::load($docfile); $fields[]; $sections = $phpWord->getSections(); foreach ($sections as $key => $value) { $sectionElement = $value->getElements(); $first=true; foreach ($sectionElement as $elementKey => $elementValue) { if($elementValue instanceof \PhpOffice\PhpWord\Element\PreserveText) { $fieldDef=$elementValue->getText(); if(count($fieldDef)==2) { array_unshift($fieldDef,""); } /** * array (size=3) 0 => string '[1=Falun Dafa is Good]' 1 => string '{FORMTEXT}' 2 => string 'SayToTheWorldField=Falun Dafa est Bon' */ list($sos_orig_text,$DATATYPE,$sos_trad_text)= $fieldDef; if($DATATYPE== '{FORMTEXT}') { $field=explode('=',$sos_trad_text."=".trim($sos_orig_text,'[]')); $fields[]=$field; }else { var_dump($elementValue->getText()); var_dump("Unsupported field Type $DATATYPE :"); die("stop"); } } echo "<pre>"; echo(htmlentities(implode("\n",$fields))); echo "</pre>";
@sos-productions
Copy link
Author

Added extra spaces for Mr Travis to be happy!

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.007%) to 94.627% when pulling a541429 on all-informatic:develop into 733f845 on PHPOffice:develop.

@PowerKiKi PowerKiKi changed the base branch from develop to master November 16, 2022 21:11
@Progi1984 Progi1984 force-pushed the master branch 3 times, most recently from 2d9f999 to e458249 Compare August 30, 2023 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants