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

Contents of the cells are not vertically centered #2583

Open
philips81 opened this issue Mar 8, 2024 · 1 comment
Open

Contents of the cells are not vertically centered #2583

philips81 opened this issue Mar 8, 2024 · 1 comment

Comments

@philips81
Copy link

Hi,
I have to use phpword 0.18.3 and when creating the tables I encounter the problem shown in the image.

$cell = $row->addCell(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(9), ['valign' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER]);

The contents of the cells are not vertically centered and I cannot do this from Office or another word editor.
Does anyone have a solution?
Thanks

Screenshot 2024-03-08 093141

@FredrikMBP
Copy link

FredrikMBP commented May 22, 2024

Hi @philips81,

I'm using 1.20 and I've been facing this issue as well. After much trial and error I found that I needed to add "spaceAfter" twice on the text in the cell.

$headerTextStyle = array(
    'bold'       => true,
    'spaceAfter' => 0
);

$textStyle = array(
    'spaceAfter' => 0
);

$tableStyle = array(
    'width'       => 100 * 50, // Word 2007 table width, in percentages, is measured in 50ths of a percent
    'unit'        => 'pct',
    'alignment'   => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER,
    'cellMargin'  => 100,
);

$table = new \PhpOffice\PhpWord\Element\Table($tableStyle);

$row = $table->addRow();
$row->addCell()->addText('Vertically centered heading', $headerTextStyle, $textStyle);

$row = $table->addRow();
$row->addCell()->addText('Vertically centered', $textStyle, textStyle);

I hope this helps!

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

2 participants