This project is read-only.

Text horizontal align in table does not work

Jan 19, 2012 at 12:40 PM

I can see from two old threads that this used to be a bug, and was fixed. I have looked at the code in the version I am running (0.6.2 beta), and can see that the documented fix exists in my version.

Nevertheless, text align horizontal still does not work.PHP5,

Any suggestions?

Here is the php:

$PHPWord = new PHPWord();
$section = $PHPWord->createSection();
$sectionStyle = $section->getSettings();
$styleTableFontHeader = array('bold'=>true, 'size' => 9, 'align'=>'right', 'valign'=>'center');//testing right align as well
$styleTableFontBody = array('bold'=>false, 'size' => 9, 'align'=>'center', 'valign'=>'center');
$tdfontStyle = array('align'=>'center', 'size' => 9);
$styleHeaderFont = array('bold'=>true, 'size' => 9, 'align'=>'left');

$styleTable = array('borderSize' => 1, 'cellMargin' => 40);
$PHPWord->addTableStyle('dataTableStyle', $styleTable);
$styleCell = array('valign' => 'center');

//we start a new table on every page, because there is no feature to repeat table first row on new page
function startNewTable () {
    global $styleCell, $styleTableFontHeader, $section;
    $table = $section->addTable('dataTableStyle');
    $table->addRow(270);
    $table->addCell(1500, $styleCell)->addText('TR Cabinet', $styleTableFontHeader);
    $table->addCell(1500, $styleCell)->addText('Zone', $styleTableFontHeader);
    $table->addCell(2000, $styleCell)->addText('RE', $styleTableFontHeader);
    $table->addCell(1800, $styleCell)->addText('Instant Off mV', $styleTableFontHeader);
    return $table;
}

######### Write each row ############
//phpword can't format a table to repeat the first row on next page,
//so we write 30 rows then page break and new table
$refs = functionToGetMyTableData()
$row = 1;
foreach ($refs as $refKey => $refData) {
    if ($row == 1) {$table = startNewTable();}
    $table->addRow(270);
    $table->addCell(1200, $styleCell)->addText($refData[0], $styleTableFontBody);
    $table->addCell(1000, $styleCell)->addText($refData[1], $styleTableFontBody);
    $table->addCell(1000, $styleCell)->addText($refData[2], $styleTableFontBody);
    $table->addCell(1000, $styleCell)->addText($refData[3], $styleTableFontBody);

    $row++;
    if ($row == 30) {
        $section->addPageBreak();
        $row = 1;
    }
}

And here is a snip from the generalted xml:

      <w:tr>
        <w:trPr>
          <w:trHeight w:val="270"/>
        </w:trPr>
        <w:tc>
          <w:tcPr>
            <w:tcW w:w="1000" w:type="dxa"/>
            <w:vAlign w:val="center"/>
          </w:tcPr>
          <w:p>
            <w:r>
              <w:rPr>
                <w:sz w:val="18"/>
                <w:szCs w:val="18"/>
              </w:rPr>
              <w:t xml:space="preserve">C001BLT 18</w:t>
            </w:r>
          </w:p>
        </w:tc>
        <w:tc>
          <w:tcPr>
            <w:tcW w:w="1000" w:type="dxa"/>
            <w:vAlign w:val="center"/>
          </w:tcPr>
          <w:p>
            <w:r>
              <w:rPr>
                <w:sz w:val="18"/>
                <w:szCs w:val="18"/>
              </w:rPr>
              <w:t xml:space="preserve">1B</w:t>
            </w:r>
          </w:p>
        </w:tc>
        <w:tc>
          <w:tcPr>
            <w:tcW w:w="1000" w:type="dxa"/>
            <w:vAlign w:val="center"/>
          </w:tcPr>
          <w:p>
            <w:r>
              <w:rPr>
                <w:sz w:val="18"/>
                <w:szCs w:val="18"/>
              </w:rPr>
              <w:t xml:space="preserve">RE-1B-1</w:t>
            </w:r>
          </w:p>
        </w:tc>
        <w:tc>
          <w:tcPr>
            <w:tcW w:w="1000" w:type="dxa"/>
            <w:vAlign w:val="center"/>
          </w:tcPr>
          <w:p>
            <w:r>
              <w:rPr>
                <w:sz w:val="18"/>
                <w:szCs w:val="18"/>
              </w:rPr>
              <w:t xml:space="preserve">-27</w:t>
            </w:r>
          </w:p>
        </w:tc>
      </w:tr>