Register Lost your password?

Blog - News

Author Archive

Text columns in a docx using PHPdocx

June 6th, 2011 | Comments Off

Need two, three or more columns for your text? You can define any number of columns you will need using this code:


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

$docx = new CreateDocx();

$text = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, ' .
    'sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut ' .
    'enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut' .
    'aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit ' .
    'in voluptate velit esse cillum dolore eu fugiat nulla pariatur. ' .
    'Excepteur sint occaecat cupidatat non proident, sunt in culpa qui ' .
    'officia deserunt mollit anim id est laborum.';

$docx->addText($text);

$paramsPage = array(
    'titlePage' => 1,
// Number of columns
    'columns' => 3,
// Orientation of the paper. Could be 'Landscape'
    'orient' => 'normal',
    'top' => 4000,
    'bottom' => 4000,
    'right' => 4000,
    'left' => 4000
);

$docx->createDocx('example_textcolumns', $paramsPage);

Adding value to variables in a PHPdocx Template

June 6th, 2011 | Comments Off

You can create templates that PHHPdocx can read and asign to any variable you add on the template a value. This basic operation with templates uses this code:


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

$docx = new CreateDocx();

$docx->addTemplate('../files/TemplateText.docx');

$docx->addTemplateVariable('WEIGHT1', '10');
$docx->addTemplateVariable('WEIGHT2', '20');
$docx->addTemplateVariable('WEIGHT3', '25');

$docx->addTemplateVariable('PRICE1', '5');
$docx->addTemplateVariable('PRICE2', '30');
$docx->addTemplateVariable('PRICE3', '7');

$docx->addTemplateVariable('TOTALWEIGHT', '55');

$docx->addTemplateVariable('TOTALPRICE', '42');

$docx->addTemplateVariable('NAME', 'David Hume');

$docx->createDocx('template_text');

Read the rest of this entry »

Reading variables in a docx template for PHPdocx

June 6th, 2011 | Comments Off

PHPdocx can use templates. You must define any variable as $variable$ in any part of text.

To recover it from a template, you must use this code:


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

$docx = new CreateDocx();

// Select the template you want to use
$docx->addTemplate('../files/TemplateText.docx');

// Recover the template's variables.
print_r($docx->getTemplateVariables());

Read the rest of this entry »

Charts and templates mix good in PHPdocx

June 6th, 2011 | Comments Off

You can define a Pie Chart in a template also to recover info more easily. Use this code to create a Pie Chart with a template.


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

$docx = new CreateDocx();

$docx->addTemplate('../files/TemplateChart.docx');

$legends = array(
    'legend1' => array(10, 11, 12),
    'legend2' => array(30, 21, 12),
    'legend3' => array(40, 41, 42)
);

$paramsChart =
    array(
        'data' => $legends,
// Use 'pieChart' if you need a classic plain Pie Chart
        'type' => 'pie3DChart',
        'title' => 'Title',
        'cornerX' => 20,
        'cornerY' => 20,
        'cornerP' => 30,
        'color' => 2,
        'textWrap' => 0,
        'sizeX' => 10,
        'sizeY' => 10,
        'jc' => 'right',
        'showPercent' => 1,
        'font' => 'Times New Roman'
    );

$docx->addTemplateChart('PIECHART', $paramsChart);

$docx->createDocx('template_chart');

Read the rest of this entry »

Adding a section to a docx document with PHPdocx

June 6th, 2011 | Comments Off

Create a section with PHPdocx is now very easy. Just use the code below: you must pass the info to PHPdocx with text, parameters of the text and also the parameters for custom de section.

here is the code:


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

$docx = new CreateDocx();

// The Text
$text = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, ' .
    'sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut ' .
    'enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut' .
    'aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit ' .
    'in voluptate velit esse cillum dolore eu fugiat nulla pariatur. ' .
    'Excepteur sint occaecat cupidatat non proident, sunt in culpa qui ' .
    'officia deserunt mollit anim id est laborum.';

$docx->addText($text);

// Text parameters
$paramsText = array(
    'b' => 'single'
);

$docx->addText($text, $paramsText);

// Custom Section
$paramsSection = array(
    'orient' => 'landscape',
    'top' => 4000,
    'bottom' => 4000,
    'right' => 4000,
    'left' => 4000
);
$docx->addSection($paramsSection);

$docx->addText($text);

$docx->addText($text, $paramsText);

$docx->createDocx('example_section');

Read the rest of this entry »