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

Using Table in string not showing properly and break file content #2354

Open
ahmedtoolapp opened this issue Dec 7, 2022 · 2 comments
Open

Comments

@ahmedtoolapp
Copy link

Describe the Bug

I can't create the table manually to PHPWord because users should be able to modify the content to export from the app, that's why I get the content and try to genrate a word file, when the string content contain table an cells , tables are not showing properly and even the file content is incomplet

A clear and concise description of what the bug is.
When content not containing table, my file is generated like a charm, but when table are there, my file is broken.
Also, when there is no tbody/thead tags : my table is here.
I found this :
Using table tag in HTML Reader produces no output
It is too old and I can't modify core code, but it seems that tbody/thead are not DOMElements.

Steps to Reproduce

Please provide a code sample that reproduces the issue.

<?php
require __DIR__ . '/vendor/autoload.php';

$html = """<html lang="fr"><body>....<table><thead><tr><th>....</th></tr></thead><tbody><tr><td>....</td></td></tbody></table>....</body></html>""" // dont work
$html = """<html lang="fr"><body>....<table><tr><td>....</td></tr><tr><td>....</td></tr></table>.....</body></html>""" // work
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
$section = $phpWord->addSection();
Html::addHtml($section, $html, true);
$objWriter = IOFactoryWord::createWriter($word);
$path = my/path;
$objWriter->save($path)

Expected Behavior

A clear and concise description of what you expected to happen.
Word file with complete content and inline designed tables.

Current Behavio

What is the current behavior?
Breaked file and tables

Context

Please fill in your environment information:

  • PHP Version: 7.4
  • PHPWord Version: 0.18.3 upgrated to 1.0.0
@ahmedtoolapp
Copy link
Author

Sorry for my english, if it's not clear
can someone help me i'm stuck and i can't get around the problem

@cavasinf
Copy link

Try using $phpWord->save() directly

$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
$header  = ['size' => 16, 'bold' => true];

$section->addText('addHtml with theader AND tbody', $header);
$table = '
    <html lang="fr"><body>
        <table>
          <thead>
            <tr>
              <th>First name</th>
              <th>Last name</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td>John</td>
              <td>Doe</td>
            </tr>
            <tr>
              <td>Jane</td>
              <td>Doe</td>
            </tr>
          </tbody>
        </table>
    </body></html>
';


PhpWordHtml::addHtml(
    $section,
    $table,
    true
);

$path = '/tmp/table.docx';
$phpWord->save($path);

Result:
table.docx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants