Export Data to Documents Set with PHP (ExportToDocSet)

The ExportToDocumentSet is a set of different PHP 5 classes which handles the export of data delivered from MySql database tables. Mainly the Visitor Design Pattern, a Debugger Class (handles all the sql database queries) and the DOM Class are reponsible for the fluent sequence of events. Microsofts Excel and Microsofts Word and Apaches Open Office text documents and table documents are also supported and can also be used as online printing facility (incl.letters in series). The necessary templates for docs and odts are easy to 'create and use': First you create your page design with your preferred Word or Open Office with specified placeholders (which are all optional) and then you safe the file as *.htm or *.html - the rest is done by the responsible class. Extra: Using Excel Files from Microsoft Excel or Table Documents from Open Office the field width will be recognized while creating the file. In total seven file types are supported: xml, csv, xls, ods, doc, odt and rtf. (see screenshots below). The setting of the ExportToDocumentSet should work for PHP 5, MySqli, Apache 2, IIS, Windows, Unix or Linux.

The scripts snippets you see here (the complete script is downloadable) is only a small part of the complete application. That's it. All stuff is all prepared for your convenience (example and class-files included). Best regards Claudio Biesele

Part of the DebugVisitor Code:

public function getFieldsFromOODBTable($tbname) {
    $this->tbname = $tbname;
    $i = '1';
    // prepare field names
    $this->fields = $this->getTableFields($this->tbname);
    while ($this->row = $this->fields->fetch_assoc()) {
        $field = ucfirst($this->row['Field']);
        $this->doccol = $this->docos->createElement('table:table-column');

        $this->doccell = $this->docos->createElement('table:table-cell');

        $this->doctext = $this->docos->createElement('text:p');
        $this->doctext_val = $this->docos->createTextNode($field);


Part of the ExportExcelVisitor Code:

public function setNewNumberFormat() {

        $this->newinteformat = $this->docxls->createElement('Interior');

        $this->newnumberformat = $this->docxls->createElement('NumberFormat');


XML file after created by ExportFleXmlVisitor Class.
CSV file after created by ExportCSVisitor Class.
Excel file after created by ExportExcelVisitor Class.
Apache Open Office ods file after created by ExportOOVisitor Class.
Microsoft Word doc file after created by ExportDocVisitor Class.
Apache Open Office odt file after created by ExportOdtVisitor Class.
Download the full script at www.fastproject.ch. The downloaded script is free from Copyright restrictions, Zurich, 07th of October 2012.