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->doccol->setAttribute('table:style-name',"co{$i}");
        $this->doccol->setAttribute('table:default-cell-style-name',"Default");
        $this->doctable->appendChild($this->doccol);

        $this->doccell = $this->docos->createElement('table:table-cell');
        $this->doccell->setAttribute('table:style-name',"ce1");
        $this->doccell->setAttribute('office:value-type',"string");

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

        $this->doccell->appendChild($this->doctext);
        $this->docrowheader->appendChild($this->doccell);
        $i++;
    }
}


Part of the ExportExcelVisitor Code:

public function setNewNumberFormat() {
        $this->setNewStyleNumberFormat();
        $this->root->appendChild($this->stylenumberformat);

        $this->newinteformat = $this->docxls->createElement('Interior');
        $this->newinteformat->setAttribute('ss:Color',"#C0C0C0");
        $this->newinteformat->setAttribute('ss:Pattern',"Solid");

        $this->newnumberformat = $this->docxls->createElement('NumberFormat');
        $this->newnumberformat->setAttribute('ss:Format',"0");

        $this->stylenumberformat->appendChild($this->newinteformat);
        $this->stylenumberformat->appendChild($this->newnumberformat);
        $this->docstylexls->appendChild($this->stylenumberformat);
        $this->root->appendChild($this->docstylexls);
}


xml_example.jpg
XML file after created by ExportFleXmlVisitor Class.
csv_example.jpg
CSV file after created by ExportCSVisitor Class.
xls_example.jpg
Excel file after created by ExportExcelVisitor Class.
ods_example.jpg
Apache Open Office ods file after created by ExportOOVisitor Class.
doc_example.jpg
Microsoft Word doc file after created by ExportDocVisitor Class.
odt_example.jpg
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.