Register Lost your password?

Hello World

PHPDOCX could not be less than other web applications so we are proud to introduce you to the “Hello World Script” that will allow you to generate, yes you guessed it right, an absurdly boring Word document with a simple “Hello World” on it.

As you can see the process is simple and a few lines of code will do, assuming you have already installed the PHPDOCX library on your web server.

The code read as follows:


require_once('../classes/cCreateDocx.inc');
$objDocx = new cCreateDocx();
$objDocx->fAddText('Hello World.');
$objDocx->fCreateDocx('hello_world.docx');

But if you are a sophisticated programmer you may try the same document with advanced formatting

You may center the text and write it in bold characters with one line more of code:


require_once('../classes/cCreateDocx.inc');
$objDocx = new cCreateDocx();
$arrParamsText = array( 'b' => 'single', 'jc' => 'center’); //b for bold and jc for alignment
$objDocx->fAddText('Hello World.', $arrParamsText);
$objDocx->fCreateDocx('hello_world.docx');

You may not get a job as a designer with the generated document but we hope it will tempt you to scan our support documentation to learn what else can be done with PHPDOCX .

pie_chart

It is obvious that a “half decent” application to generate reports has to include a tool for the creation of charts and graphs on the fly, so PHPDOCX could not do less than that.
In fact PHPDOCX is a pretty sophisticated tool to that regard and as we show below is very simple to generate a nice chart from some data that could be extracted from a database, a spreadsheet or elsewhere.

In this example we will concentrate in creating a pie chart that plots the following sample data:

Do you like “paella”?
Like paella: 50%
Don´t like paella: 10%
What the f*** is a paella? : 40%
Notice: paella is a typical Spanish rice dish.


require_once('../classes/cCreateDocx.inc');
$objDocx = new cCreateDocx();
$arrDatos = array( 'like paella' => array(50), 'do not like paella' => array(10), 'what the f***…?' => array(40) );
$arrArgs = array('data' => $arrDatos, 'type' => 'pieChart', 'title' => 'Do you like paella?', 'showPercent' => 1 );
$objDocx->fAddGraphic($arrArgs);
$objDocx->fCreateDocx('simple_piechart');



That generates this pie chart.

If you prefer a 3D version of this pie chart you need the Pro version but the required code is not much different:


require_once('../classes/cCreateDocx.inc');
$objDocx = new cCreateDocx();
$arrDatos = array( 'like paella' => array(50), 'do not like paella' => array(10), 'what the f***…?' => array(40) );
$arrArgs = array('data' => $arrDatos, 'type' => 'pie3DChart', 'title' => 'Do you like paella?', 'showPercent' => 1 );
$objDocx->fAddGraphic($arrArgs);
$objDocx->fCreateDocx('simple_piechart');

Why Phpdocx ?

Microsoft Word™ is the de facto standard for word processing and as such is widely use in a great variety of professional environments and since 2003 is also part of an open standard (OOML) based on XML.

Despite this fact, there has been little effort from the open source community to develop tools that allow the programatical creation of word documents (.docx), something that could be a result of the aversion of many programmers with respect the Microsoft “evil empire”.

It is not among our objectives to endorse or support any specific standard or company but we believe that a tool like PHPDOCX can be of much help to all of those web developers that struggle to generate reports in Word format.

PHPDOCX was born from our own need to generate editable reports for our clients on a LAMP (Linux-Apache-MySQL-PHP) platform (although the “P” of PHP is the only required acronym to run PHPDOCX on a web server).

We offer PHPDOCX in two different ways:

  • Free version: that allows, at no cost, for the creation of basic documents in the .docx format.
  • Pro version: that allows more sophisticated formatting at extra, although very low, cost.

Although the free version will be sufficient for the majority of applications it cannot be upgraded to include support and lacks some of the flexibility and scalability of the Pro version.
We hope that you consider this PHP library useful and we wait for your feedback to improve it