trollolodn icon

#php #SimpleExcel export array 2 xml

trollolodn | PRO | 01/23/13 04:01:11 AM UTC | 0 ⭐ | 145 👁️ | Never ⏰ | []
PHP |

790 B

|

None

|

0 👍

/

0 👎

// *Note Download SimpleExcel : http://faisalman.github.com/simple-excel-php/
// *twitter.com/quocvuongdn
 
use SimpleExcel\SimpleExcel;
 
require '../lib/SimpleExcel/SimpleExcel.php';
 
public function exportToXml($results,$fileName){ //$result is ResultSet from query DB, $fileName is name of xml file.
        //Export to xml, can see it on excel office.
        $rowHead = array();
        foreach ($results[0] as $key => $value) {
            array_push($rowHead, $key);
        }
 
        $rowData = array();
        array_push($rowData, $rowHead); //Put column name to [0] position array.
 
        foreach ($results as $key => $value) {
            array_push($rowData, $value); //Put data to array.
        }
 
        $this->excel->writer->setData($rowData); //Set array to data of xml file.
        $this->excel->writer->saveFile($fileName); //Set name file.
    }

Comments