Tables


// create empty document and append paragraph
$doc = new PNDocx();
$p = $doc->appendParagraph();

// create the data for a table
$rawTable = array();
$rawTable[0][0] = "First row, first column";
$rawTable[0][1] = "First row, second column";
$rawTable[1][0] = "Second row, first column";
$rawTable[1][1] = "Second row, second column";
$rawTable[2][0] = "...";
$rawTable[2][1] = "...";
$rawTable[3][0] = "...";
$rawTable[3][1] = "...";

// create a table before our pragraph and 
// remove the pragraph
$table = $p->tableBefore($rawTable);
$p->remove();

// perform operations on all cells
$table->row()->cell()->borders();
$table->row()->cell()->p()->center();
$table->row()->cell()->p()->singled();
$table->row()->cell()->p()->run()->font("Calibri");

// set some text
$table->setText(3, 1, "Fourth row, second column");

// merge cells
$table->row(2)->cell(0)->mergeRight();

// send document to browser
$doc->send();

Show the result

  1. No comments yet.
  1. No trackbacks yet.
You must be logged in to post a comment.