Forum


Replies: 3   Views: 3488
Bug - cannot put text and list in same row in a 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 webdzinez  · 08-10-2013 - 09:21

I have tried several ways to do this (below is code). Here is what I am trying to do simply



<table row1>



Intro text



-list item1



-list item2



</table row1>



 



Here is the code:



 



<?php



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



$docx = new CreateDocx(); //creates a document instance





//Table values, basically 2 columns

$valuesTable = array(

    array(

        11,

        12

    ),

    array(

        21,

        22

    ),

);



$paramsTable = array(

    'border' => 'single',

    'border_sz' => 4,

    'rawWordML' => true

);





//created a table out of nothing

$myTable = $docx->addTable($valuesTable, $paramsTable);



$fragment = $docx->createWordMLFragment(array($myTable, $myTable));





//we can use fragments as values inside table

//Rules:

//1. if its in same row, it has to be part of same array within the table

//2. We will create a simple text first and create a fragment out of it. Call it textFragment

//3. We will create a simple list and create a fragment out of it. Call it listFragment

//4. Finally we would put them into our values table as two elements of an array





//[2]



$text = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit';

$paragraphoptions = array(

    'b' => 'on',

    'font' => 'Arial',

    'rawWordML' => true, //must be true otherwise never would return anything. IMPORTANT: This is fundamental difference between adding text and adding table. When you addText directly to the doc, you dont specify this as true.

);

$textToAdd = $docx->addText($text, $paragraphOptions); //returns a string with raw ML code, but not rawML code itself

$textFragment = $docx->createWordMLFragment(array($textToAdd));





//[3]



$itemList = array(

    'Line 1',

    'Line 2',

    'Line 3',

    'Line 4',

    'Line 5'

);



$options = array(

    'val' => 1, 

    'rawWordML' => true, //must be true otherwise never would return anything. IMPORTANT: This is fundamental difference between adding text and adding table. When you addText directly to the doc, you dont specify this as true.

);



$listToAdd = $docx->addList($itemList    , $options);

$listFragment = $docx->createWordMLFragment(array($listToAdd));



//Now we have two fragments that we will put into our list



/*

IMPORTANT: //THIS GIVES A PROBLEM. DOESNT LIKE TEXT FRAGMENTS IN VALUES, BUT CAN DIRECTLY ADD A STRING HERE. GIVES WORD ENCOUNTERED A PROBLEM WHEN OPEN



$valuesTable2 = array(

    array(

        a,

        b

    ),

    array(

        $textFragment, 

        $listFragment

    ),

);

*/



/*

IMPORTANT: //THIS WORKS FINE, but text and list in separate columns. Getting there



$valuesTable2 = array(

    array(

        a,

        b

    ),

    array(

        'I work fine', 

        $listFragment

    ),

);

*/





/*

//IMPORTANT: //THE CODE RUNS, NO ERROR ON OPENING OF THE FILE BUT NO TEXT SHOWN. 



$totalfragment = $docx->createWordMLFragment(array($listToAdd, $textToAdd));



$valuesTable2 = array(

    array(

        a,

        b

    ),

    array(

        'My code runs, word opens fine, but I dont show the added text. It is as if the fragment doesnt created through AddText function', 

        $totalfragment

    ),

);



$paramsTable2 = array(

    'border' => 'single',

    'border_sz' => 20

);



*/





/*

//IMPORTANT: //THE CODE RUNS, NO ERROR ON OPENING OF THE FILE BUT THE TEXT IS OUT OF THE BOUNDS . 



$totalfragment1 = $docx->createWordMLFragment(array($listToAdd, 'My new text'));



$valuesTable2 = array(

    array(

        a,

        b

    ),

    array(

        'My code runs, word opens fine, the added text is not part of the table. It is as if the fragment doesnt created through AddText function', 

        $totalfragment1

    ),

);



*/





$paramsTable2 = array(

    'border' => 'single',

    'border_sz' => 20

);





$docx->addTable($valuesTable2, $paramsTable2);



$docx->createDocx('voodoo');





?>