trollolodn

#php #SimpleExcel export array 2 xml

Jan 22nd, 2013
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.79 KB | None | 0 0
  1. // *Note Download SimpleExcel : http://faisalman.github.com/simple-excel-php/
  2. // *twitter.com/quocvuongdn
  3.  
  4. use SimpleExcel\SimpleExcel;
  5.  
  6. require '../lib/SimpleExcel/SimpleExcel.php';
  7.  
  8. public function exportToXml($results,$fileName){ //$result is ResultSet from query DB, $fileName is name of xml file.
  9.         //Export to xml, can see it on excel office.
  10.         $rowHead = array();
  11.         foreach ($results[0] as $key => $value) {
  12.             array_push($rowHead, $key);
  13.         }
  14.  
  15.         $rowData = array();
  16.         array_push($rowData, $rowHead); //Put column name to [0] position array.
  17.  
  18.         foreach ($results as $key => $value) {
  19.             array_push($rowData, $value); //Put data to array.
  20.         }
  21.  
  22.         $this->excel->writer->setData($rowData); //Set array to data of xml file.
  23.         $this->excel->writer->saveFile($fileName); //Set name file.
  24.     }
Advertisement
Add Comment
Please, Sign In to add comment