Forum


Replies: 7   Views: 6019
Horizontal aligment in table cell?
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 lamador  · 21-04-2014 - 10:32

Hello,



Is posible set the horizontal aligment of just one cell using the addTable function. I see there is a 'vAlign' parameter but I can't find one for the horizontal aligment. 



Thank you.


Posted by lamador  · 21-04-2014 - 10:52

Done it!



I did it using the addText function with the 'jc' parameter. 



Thanks anyway!


Posted by neiron  · 01-11-2015 - 11:04

Please write an example, I do not understand how to use addText()

Posted by neiron  · 01-11-2015 - 11:25

$text = '123';
$paragraphOptions = array(
  'jc' => 'center'
);
$par = $docx->addText($text, $paragraphOptions);


$data[] = array(
  array(
    'value' => $par,
    'cellMargin' => 200,
    'rowspan' => 2,
  )
 );

 

not working :(

Posted by neiron  · 02-11-2015 - 15:34

Ok!.

How do I align text in a cell in the middle?

Example:

$docx = new CreateDocx();
$data[] = array(
  array(
    'value' => 'text1',
    'vAlign' => 'center'
  ),
  array(
   'value' => 'text2', 
   vAlign' => 'center'
  )
)

 

$paramsTable = array(
  'border' => 'none',
  'tableAlign' => 'center',
  'textProperties' => array('font' => 'Arial', 'fontSize' => 10),
);
$docx->addTable($data, $paramsTable, array(
  0 => array('tableHeader' => TRUE),
));

$docx->createDocxAndDownload('report.docx');

Posted by admin  · 03-11-2015 - 09:17

Hello,

This is a simple example to add centered text:

<?php

require_once '../../classes/CreateDocx.inc';

$docx = new CreateDocx();

$textFragment = new WordFragment($docx);
$text = array();
$text[] =
    array(
        'text' => 'Centered text',
        'underline' => 'single'
    );
$paragraphOptions = array(
    'textAlign' => 'center',
);
$textFragment->addText($text, $paragraphOptions);

$valuesTable = array(
    array(
        $textFragment,
    ),
    array(
        'Other text',
    ),
    array(
        'Other text',
    ),
);

$docx->addTable($valuesTable);

$docx->createDocx('output');

Regards.

Posted by neiron  · 03-11-2015 - 09:30

Thanks you very much. That's it. that it is necessary for me. A bit strange that for vertical alignment is defined as simple, and for horizontal alignment should be used WordFragment () + addText ().

Thank you again. This is the best library for docx. These are the best admins.