fix broken samples

This commit is contained in:
troosan 2018-12-30 01:13:54 +01:00
parent 54e7c6dd5a
commit b375b8580f
4 changed files with 19 additions and 20 deletions

View File

@ -7,13 +7,8 @@ $source = "resources/{$name}.doc";
echo date('H:i:s'), " Reading contents from `{$source}`", EOL; echo date('H:i:s'), " Reading contents from `{$source}`", EOL;
$phpWord = \PhpOffice\PhpWord\IOFactory::load($source, 'MsDoc'); $phpWord = \PhpOffice\PhpWord\IOFactory::load($source, 'MsDoc');
// (Re)write contents // Save file
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf'); echo write($phpWord, basename(__FILE__, '.php'), $writers);
foreach ($writers as $writer => $extension) { if (!CLI) {
echo date('H:i:s'), " Write to {$writer} format", EOL; include_once 'Sample_Footer.php';
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
$xmlWriter->save("{$name}.{$extension}");
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
} }
include_once 'Sample_Footer.php';

View File

@ -14,7 +14,7 @@ $templateProcessor->deleteBlock('DELETEME');
echo date('H:i:s'), ' Saving the result document...', EOL; echo date('H:i:s'), ' Saving the result document...', EOL;
$templateProcessor->saveAs('results/Sample_23_TemplateBlock.docx'); $templateProcessor->saveAs('results/Sample_23_TemplateBlock.docx');
echo getEndingNotes(array('Word2007' => 'docx'), 'results/Sample_23_TemplateBlock.docx'); echo getEndingNotes(array('Word2007' => 'docx'), 'Sample_23_TemplateBlock');
if (!CLI) { if (!CLI) {
include_once 'Sample_Footer.php'; include_once 'Sample_Footer.php';
} }

View File

@ -17,9 +17,9 @@
<h2>Includes images</h2> <h2>Includes images</h2>
<img src="https://phpword.readthedocs.io/en/latest/_images/phpword.png" alt=""/> <img src="https://phpword.readthedocs.io/en/latest/_images/phpword.png" alt=""/>
<img src="https://localhost/gev/desarrollo/actividades/pruebas_14/5b064503587f7.jpeg" name="Imagen 12" align="bottom" width="208" height="183" border="0"/> <img src="http://php.net/images/logos/php-med-trans-light.gif" name="Imagen 12" align="bottom" width="208" height="183" border="0"/>
<img src="http://localhost/gev/desarrollo/actividades/pruebas_14/5b064503589db.png" name="Imagen 13" align="bottom" width="143" height="202" border="0"/> <img src="http://php.net/images/logos/php-icon.png" name="Imagen 13" align="bottom" width="143" height="202" border="0"/>
<img src="http://localhost/gev/desarrollo/actividades/pruebas_14/5b0645035aac8.jpeg" name="Imagen 14" align="bottom" width="194" height="188" border="0"/> <img src="http://php.net/images/logos/php-med-trans-light.gif" name="Imagen 14" align="bottom" width="194" height="188" border="0"/>
</body> </body>
</html> </html>

View File

@ -107,20 +107,24 @@ class Table extends AbstractElement
/** /**
* Translates Table style in CSS equivalent * Translates Table style in CSS equivalent
* *
* @param \PhpOffice\PhpWord\Style\Table|null $tableStyle * @param string|\PhpOffice\PhpWord\Style\Table|null $tableStyle
* @return string * @return string
*/ */
private function getTableStyle(\PhpOffice\PhpWord\Style\Table $tableStyle = null) private function getTableStyle($tableStyle = null)
{ {
if ($tableStyle == null) { if ($tableStyle == null) {
return ''; return '';
} }
if (is_string($tableStyle)) {
$style = ' class="' . $tableStyle;
} else {
$style = ' style="'; $style = ' style="';
if ($tableStyle->getLayout() == \PhpOffice\PhpWord\Style\Table::LAYOUT_FIXED) { if ($tableStyle->getLayout() == \PhpOffice\PhpWord\Style\Table::LAYOUT_FIXED) {
$style .= 'table-layout: fixed;'; $style .= 'table-layout: fixed;';
} elseif ($tableStyle->getLayout() == \PhpOffice\PhpWord\Style\Table::LAYOUT_AUTO) { } elseif ($tableStyle->getLayout() == \PhpOffice\PhpWord\Style\Table::LAYOUT_AUTO) {
$style .= 'table-layout: auto;'; $style .= 'table-layout: auto;';
} }
}
return $style . '"'; return $style . '"';
} }