DOCX TO HTML USING PHP - PullRequest
       7

DOCX TO HTML USING PHP

0 голосов
/ 11 апреля 2020

Я хочу преобразовать документ (.docx) в HTML, используя PHP. Чтобы объяснить больше, я хочу, чтобы код php генерировал стиль и заголовки и преобразовывал их в html (h1, p, ...). Но мой код, похоже, не распознает стиль, какая-либо помощь?

<?php 
require_once '../vendor/autoload.php';

if (isset($_POST['nom'])) {

    // La creature d'un nouveau objet word (phpword) et un objet lecteur
    $objReader = \PhpOffice\PhpWord\IOFactory::createReader('Word2007');
    $nomF = $_POST['nom'];
    $phpWord = $objReader->load($nomF);



    //pour lire et ecrire le contenu sur la page web selon les sections et les elements


    $sections = $phpWord->getSections();
    foreach ($sections as $key => $value) {
        $sectionElement = $value->getElements();
        foreach ($sectionElement as $elementKey => $elementValue) {
            if ($elementValue instanceof \PhpOffice\PhpWord\Element\TextRun) {
                $secondSectionElement = $elementValue->getElements();
                foreach ($secondSectionElement as $secondSectionElementKey => $secondSectionElementValue) {
                    if ($secondSectionElementValue instanceof \PhpOffice\PhpWord\Element\Text) {
                        echo $secondSectionElementValue->getText();
                        echo "<br>";
                    }
                }
            }
        }
    }



    //pour ecrir le contenu dans un nouveau fichier world
    $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
    $objWriter->save('Word7.docx');

    $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'HTML');
    $objWriter->save('word7.html');
}
?>
...