Forum


Replies: 5   Views: 2182
Table with empty cell and space after table
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by marius.janulaitis  · 26-02-2020 - 09:32

Hi,
i have two issues with table:
1. When one of table cell is empty, row with this cell is with corrupted style. Extra space appears and the cursor appears at the top of the cell.
2. After table i need to add text with style. Before text should be one line. If text without any tag, then <br> works perfect, but when text is with tage appears extra space.

Here is my file: https://imgur.com/a/LuVduvD

Code:

<?php
require_once 'classes/CreateDocx.php';
$createDocx = new CreateDocx();
$createDocx->setDefaultFont('Verdana');
$createDocx->setDocumentDefaultStyles(['fontSize' => 15]);
  
$html = '<style>
    body{
        font-family: Verdana, sans-serif!important;
        font-size: 10px!important;
    }
    table {
        font-family: Verdana, sans-serif!important;
        font-size: 10px!important;
        line-height: 10px;
    }
    table.full-borders {
        width: 100%;
        border-collapse: collapse;
    }
    table.full-borders, .full-borders td, .full-borders th {
        border: 1px solid black;
        padding-left: 5px;
    }
</style>
<div>
    1. Table title:
</div>
<table class="table-full full-borders" width="600" cellspacing="0">
    <tr>
        <td width="300">1 Lorem ipsum dolor</td>
        <td width="300">Lorem ipsum dolor</td>
    </tr>
    <tr>
        <td>2 Quisque ac augue eu nibh</td>
        <td></td>
    </tr>
        <tr>
        <td>3 Quisque ac augue eu nibh</td>
        <td>augue eu nibh</td>
    </tr>
</table>
<br>
<div style="font-weight: bold;">First new line</div><br>
2 new line<br>
3 new line<br>
4 new line<br><br>
5 Second new line';

$html .= '<table style="display: none;">
        <tbody>
                <tr>
                        <td></td>
                </tr>
        </tbody>
</table>';

$createDocx->embedHTML($html);
$createDocx->createDocx('output');

 

Posted by admin  · 26-02-2020 - 12:22

Hello,

What license (Trial, Basic, Advanced, Premium) and version of phpdocx are you using?

Redards.

Posted by marius.janulaitis  · 26-02-2020 - 16:08

I have "Basic", phpdocx 9.5.

Posted by admin  · 26-02-2020 - 17:01

Hello,

Thanks for sending the requested information.

About your questions:

1. When one of table cell is empty, row with this cell is with corrupted style. Extra space appears and the cursor appears at the top of the cell.

Text styles aren't applied to cells but contents. So if you want to apply a content style, you need to add a blank space at least:

<tr>
    <td>2 Quisque ac augue eu nibh</td>
    <td>&nbsp;</td>
</tr>

Otherwise, no style is added and the default styles are used when writing content.

2. After table i need to add text with style. Before text should be one line. If text without any tag, then <br> works perfect, but when text is with tage appears extra space.

A <br> tag generates a w:br tag inside the w:p tag (paragraph tag). The extra space you see is from the paragraph generated when adding the content, that doesn't have the same size than a break tag. We recommend you to wrap the contents in a paragraph and apply the needed styles (margin, padding...) to get the output you want:

<p>
<div style="font-weight: bold;">First new line</div><br>
2 new line<br>
3 new line<br>
4 new line<br><br>
5 Second new line'
</p>

Regards.

Posted by marius.janulaitis  · 27-02-2020 - 13:00

Hi,
thank you very much for your reply.

1. I thought about it, but the blank space symbol generates a gray rectangle.
Please take a look here: https://ibb.co/GR6rCrN
Of course, this is not a big problem, but it could have been better. 

2. <p> tag with <div> - in this case, the text sticks to the table. 
I need to make a one line space (<br>) and <p> tag with <span> it does, but only in Open Offce. 
There is a problem with Google DOC, please take a look here: https://ibb.co/tLjgjNn
As you can see, the text sticks to the table again.

Posted by admin  · 27-02-2020 - 15:41

Hello,

That gray rectangle doesn't appear using MS Word, it seems a LibreOffice/OpenOffice limitation, you can use &ensp; to avoid it:

<tr>
    <td>2 Quisque ac augue eu nibh</td>
    <td>&ensp;</td>
</tr>

About the other question, Google Docs has many limitations when working with DOCX documents (for example adding charts and other complex contents) as it doesn't comply with the OOXML standard correctly. You'll need to mix paragraph margins/paddings and line breaks to get the needed output.

Regards.