Es gibt gute PHP-Bibliothek, aber es ist nicht frei: http://www.phpdocx.com/documentation/introduction/html-to-word-PHP
Wenn Sie nur ersetzen möchten einen Text in der Textvorlage (Ich schlage vor, dass Sie docx-Format verwenden) Sie docx-Datei entpacken kann und Sie finden XML-Datei diesen Inhalt.
Sie können also str_replace ('{{youVariableInWordTemplate}}', $ value, $ wordXML);
Eine andere Möglichkeit: Verwenden Sie PhpWord
$phpWord = new PhpWord();
$section = $phpWord->addSection();
$html = '<p><strong>You html here</strong></p>';
Html::addHtml($section, $html);
$objWriter = IOFactory::createWriter($phpWord, 'Word2007');
$cacheDir = '/temp_directory_of_your_project/';
$objWriter->save($cacheDir. 'helloWorld.docx');
Aber diese Bibliothek hat Problem mit Tabellenerzeugungs. Es ist Ausgabe geöffnet: Using table tag in HTML Reader produces no output mit Lösung benutzerdefinierten Klasse zu verwenden (siehe Anhang in der post)
Sie können auch eine verbesserte Implementierung finden: HTML Reader from PHPWord does't work with tables?
Diese Bibliothek Unterstützung nicht viele HTML-Tags (Array mit unterstützten Tags unten):
$nodes = array(
// $method $node $element $styles $data $argument1 $argument2
'p' => array('Paragraph', $node, $element, $styles, null, null, null),
'h1' => array('Heading', null, $element, $styles, null, 'Heading1', null),
'h2' => array('Heading', null, $element, $styles, null, 'Heading2', null),
'h3' => array('Heading', null, $element, $styles, null, 'Heading3', null),
'h4' => array('Heading', null, $element, $styles, null, 'Heading4', null),
'h5' => array('Heading', null, $element, $styles, null, 'Heading5', null),
'h6' => array('Heading', null, $element, $styles, null, 'Heading6', null),
'#text' => array('Text', $node, $element, $styles, null, null, null),
'span' => array('Span', $node, null, $styles, null, null, null), //to catch inline span style changes
'strong' => array('Property', null, null, $styles, null, 'bold', true),
'em' => array('Property', null, null, $styles, null, 'italic', true),
'sup' => array('Property', null, null, $styles, null, 'superScript', true),
'sub' => array('Property', null, null, $styles, null, 'subScript', true),
'table' => array('Table', $node, $element, $styles, null, 'addTable', true),
'tbody' => array('Table', $node, $element, $styles, null, 'skipTbody', true), //added to catch tbody in html.
'tr' => array('Table', $node, $element, $styles, null, 'addRow', true),
'td' => array('Table', $node, $element, $styles, null, 'addCell', true),
'ul' => array('List', null, null, $styles, $data, 3, null),
'ol' => array('List', null, null, $styles, $data, 7, null),
'li' => array('ListItem', $node, $element, $styles, $data, null, null),
);
Wer hat Ihnen gesagt, dass * Snippet * würde HTML in eine richtige Word-Datei konvertieren? Es sendet lediglich einen gefälschten Content-Type. (Es sei denn es andere Code haben Sie nicht gezeigt.) – mario
* bedeutet html doc Datenkonvertierung nicht * funktioniert natürlich ... es gibt keine Konvertierung – donald123
HTML-Markup in einer Datei mit dem Namen ist weder 'doc', noch' docx '; es ist einfach HTML-Markup in einer Datei mit einer anderen Erweiterung –