Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reading more than docx from database to generate new docx #1333

Open
SomayaMomtaz opened this issue Apr 6, 2018 · 0 comments
Open

Reading more than docx from database to generate new docx #1333

SomayaMomtaz opened this issue Apr 6, 2018 · 0 comments

Comments

@SomayaMomtaz
Copy link

SomayaMomtaz commented Apr 6, 2018

I'm trying to read 2 docx files or more from database and write all of it in new docx and may add text after
but it only read one file and don't even read the text below the loop
i'm new to php and phpword
using netbean IDE 8.0.2
windows 7

this is a code sample that reproduces the issue.

$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);
        //save docx file    
        $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
        $objWriter->save('Generated Files/' . $GenFileName . '.docx');
    }    //end of main if statment 
    //If the exception is thrown, this text will not be shown
    echo 'If you see this, the number is 1 or below';
} // end of try
catch (PDOException $e) {
    echo "Error: " . $e->getMessage();
}

mysqli_close($conn);

### Context

* PHP version: 5
* PHPWord version: 0.14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant