Register Lost your password?
Full api documentation: full api documentation FREE version full api documentation PRO version

public function addTable(array table, array paramsTable = array())

Parameters

$table

  • data for the table



$paramsTable

  • ‘border’ (border type) : none, single, double
  • ‘border_spacing’ (spacing) : 0, 1, 2,…
  • ‘border_color’ (border color) : ffffff, ff0000, …
  • ‘border_sz’ (border size) : 10,…
  • ‘jc’ (table alignment) : center, right
  • ’size_col’ (column size) : 1200,…
  • ‘TBLSTYLEval’ (table style): TableGrid(without border), Cuadrculamedia3-nfasis1(displayed rows with bands), Sombreadomedio1(displayed columns with bands), Tablaconcuadrcula(Table with borders)
  • ‘font’ (A specific size and style of font type within a type family. Example ‘Times New Roman’, ‘Arial’,…)

Examples

Example 1


require_once 'classes/CreateDocx.inc';

$docx = new CreateDocx();

$valuesTable = array(
    array(
        11,
        12
    ),
    array(
        21,
        22
    ),
);

$paramsTable = array(
    'border' => 'single',
    'border_sz' => 20
);

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

$docx->createDocx('example_table');


Example 2 Version Pro


require_once 'classes/CreateDocx.inc';

$docx = new CreateDocx();

$paramsLink = array(
    'title' => 'Link to Google',
    'link' => 'http://www.google.es'
);

$link = $docx->addElement('addLink', $paramsLink);

$paramsImg = array(
    'name' => '../files/img/image.png'
);

$image = $docx->addElement('addImage', $paramsImg);

$valuesTable = array(
    array(
        'Title A',
        'Title B',
        'Title C',
    ),
    array(
        'Line A',
        $link,
        $image,
    )
);

$paramsTable = array(
    'TBLLOOKval' => 'ffff01E0',
    'TBLSTYLEval' => 'Tablanormal',
    'TBLWtype' => 'center',
    'TBLWw' => '50',
    'border' => 'single',
    'border_sz' => 20,
    'border_spacing' => 0,
    'border_color' => 'ff0000',
    'jc' => 'center',
    'size_col' => 1200
);

$docx->addTable($valuesTable, $paramsTable);
$docx->createDocx('example_table');

    7 Responses

  • cbrett

    Is it possible to merge table cells?

  • What’s new on PHPdocX 1.6? | PHPDOCX

    [...] are two new functions for tables and templates: fAddTable and [...]

  • Herschel

    How can I create my own table style, or specifically how do I shade the cells in my first row (the column headers) to blue?

  • raoulhira

    Currently using PHPDocX 2.3, is it possible to merge cells?

  • mees

    size_col parameter, how does this work?
    Is it possible to set the column with of each column in a table?

  • nachtschicht

    Is there a way to define a background color for a cell?

  • nachtschicht

    Ok found the background color parameter name (’cell_color’). Now I am looking vor a way to set the vertical allignment for a row to center. Any suggestions?

Your comments