1

我正在尝试从数据库中读取 2 个或更多 docx 文件并将其全部写入新 docx 并可能在之后添加文本,但它只读取一个文件,甚至不读取循环下方的文本我是 php 新手和phpword 我使用的是 netbean IDE 8.0.2

这是我的代码:

$phpWord = new \PhpOffice\PhpWord\PhpWord();
$phpWord->getSettings()->setThemeFontLang($languageEnGb);

try {
    include ('DbConnection.php');

    $GenratedFileID = "1";
    $GenFileName = '';
    $sql = "SELECT S.FileID as fileID, G.GenratedFileName as GenFile, L.FileName 
 as Fname , L.FilePath as FilePth,"
        . "G.GenratedFileName as GName "
        . "FROM sections S,genratedfiles G, fileslibrary L "
        . " where G.GenratedFileID = S.GenratedFileID "
        . "and S.FileID = L.FileID and G.GenratedFileID =" . 
    $GenratedFileID;
    $result = $conn->query($sql);
    if ($result->num_rows > 0) {

        while ($row = $result->fetch_assoc()) {            //Read Library File
            $GenFileName = $row['GName'];
            $name = str_replace('/', '\\', $row['FilePth']);
            $source = __DIR__ . "\\{$name}";

            $phpWord = \PhpOffice\PhpWord\IOFactory::load($source);
        }//end of while loop
        //  $section->addOLEObject($row['FilePth']);
        $section = $phpWord->addSection();
        $section->addTitle('Welcome to first database Genrated File', 1);
        $section->addText('created by me');
        $section->addTextBreak(2);


        $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
        $objWriter->save('Generated Files/' . $GenFileName . '.docx');
    }
} 
catch (PDOException $e) {
    echo "Error: " . $e->getMessage();
}

mysqli_close($conn);
4

0 回答 0