Need to add/remove bulleted text and rows in a table, dynamically

Nov 30, 2010 at 11:14 AM

Sorry to say that I don't think PHPWord is sufficient enough to modify a docx dynamically. Basically my requirement is adding some bullet-ed texts following on the same bullet-ed styled texts in the existing docx, adding/ removing some rows & columns in a table in the existing docx, keeping their existing styles. Using ZipArchive I've successfully replaced/modified some strings in the docx but stuck with bullets and tables modifications. Any help please?

Nov 30, 2010 at 1:31 PM

I would like to help, but I am not sure what you mean. I have a complex table in my docx.

I use a $columnHeadings var and a foreach loop to control the number of columns. Of course, the number of cells in the row should match the number of $columnHeadings. You could use a foreach loop with $cells var to build each row.

// Add table for members
$tableStyle = array('borderSize' => 6, 'borderColor' => '999999', 'cellMargin' => 20);
$firstRowStyle = array ('bgColor' => 'EEEEEE');
$PHPWord->addTableStyle('myStyle', $tableStyle, $firstRowStyle);
$table = $section->addTable('myStyle');
$table->addRow();

// heading row
$headFontStyle = array('size' => 11, 'bold' => true);
foreach ($columnHeadings as $head)
{
  $table->addCell(1300, $cellStyle)->addText($head, $headFontStyle, $paraStyle);
}
// member rows
foreach ($members as $member)
{
  $photoStyle = array('width' => 80);
  $table->addRow();
  $table->addCell(1300, $cellStyle)->addImage('/myfull/path'.($member->getImage() ? $member->getImage() : $member->getDefaultImage()), $photoStyle);
  $table->addCell(1300, $cellStyle)->addText($member->getFullName());
  $statusCell = $table->addCell(1300, $cellStyle);
    $statusCell->addImage('/myfull/path'.$member->getMemberStatusIcon()); //makes a linebreak after the image insert! How to remove linebreak??
    $statusCell->addText($member->getMemberStatusWord());
  $table->addCell(1300, $cellStyle)->addText($member->getTitle());
  $table->addCell(1300, $cellStyle)->addText($member->getAssignedSA());
  $table->addCell(1300, $cellStyle)->addText($member->getAccessGroup());
  $table->addCell(1300, $cellStyle)->addText($member->getComment());
}

// footer row
$table->addRow();
$lastRowStyle = array ('bgColor' => 'EEEEEE');
for ($i = 1; $i <= count($columnHeadings); $i++)
{
  $table->addCell(1300, $lastRowStyle);
}


Dec 1, 2010 at 5:09 AM

i have a sample docx like the following. and the bullet style and table texts/ rows/ columns and their styles could be varied from verdana to arial or from font size 8 to 20 pt. etc.

say there are some bullets like this-

 

  • %BULLETEDITEM%

 

  • %BULLETEDITEM%

say there is a table like this-

%ITEMONE%

%ITEMTWO%

%ITEMTHREE%

ok? now i need to follow the exact existing styles for bullets and tables when i am adding new bullets or new rows in a table. please note as per your example code, i cant determine "

$tableStyle = array('borderSize' => 6, 'borderColor' => '999999', 'cellMargin' => 20);" because i don't know whether the current style has a border or not, or what should be its background color!

so i need to know the styles on the fly then by following them need to add bullet-ed texts dynamically. the same rule applies to tables also :)

does this make sense now?