'PHPWORD generates "mirrored" table instead of normal

I use PHPWORD library to generate .docx document with a simple table.

This is the code:

require "vendor/autoload.php";
$phpWord = new  \PhpOffice\PhpWord\PhpWord();

$phpWord->setDefaultFontName('Arial');
$phpWord->setDefaultFontSize(12);

$properties = $phpWord->getDocInfo();

$properties->setCreator('My doc');
$properties->setCompany('My doc');
$properties->setTitle('My doc');
$properties->setDescription('My doc');
$properties->setCategory('My doc');
$properties->setLastModifiedBy('My doc');
$properties->setCreated(time());
$properties->setModified(time());
$properties->setSubject('My doc');
$properties->setKeywords('My, Doc, Yeah');

$sectionStyle = array(
                    
                    'orientation' => 'portrait',
                    'marginTop' => \PhpOffice\PhpWord\Shared\Converter::pixelToTwip(40),
                    'marginLeft' => \PhpOffice\PhpWord\Shared\Converter::pixelToTwip(40),
                    'marginRight' => \PhpOffice\PhpWord\Shared\Converter::pixelToTwip(40),
                    'colsNum' => 1,
                    'pageNumberingStart' => 1,
                    'borderBottomSize'=>100,
                    'borderBottomColor'=>'ffffff'
                
                    );
$section = $phpWord->addSection($sectionStyle);

$html2 = '<table>';
$html2 .= '<tr>';
$html2 .= '<td>Something 1</td>';
$html2 .= '<td>Something 2</td>';
$html2 .= '</tr>';
$html2 .= '<tr>';
$html2 .= '<td>Another 1</td>';
$html2 .= '<td>Another 2</td>';
$html2 .= '</tr>';
$html2 .= '</table>';

\PhpOffice\PhpWord\Shared\Html::addHtml($section, $html2);
header("Content-Description: File Transfer");
header('Content-Disposition: attachment; filename="first.docx"');
header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Expires: 0');

$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$xmlWriter->save("php://output");

So the document is generated, but the table in it is shown not like this:

Something 1 | Something 2

Another 1 | Another 2

But like this:

Something 2 | Something 1

Another 2 | Another 1

So for some reason it is "mirrored" in generated .docx. Here is an attached imaged of the .docx - https://ibb.co/1McSS0y. What is the reason?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source