Example #1
0
 function ExcelOutput($query = "")
 {
     //connect mysql database
     mysql_select_db($this->db_name, $this->db_link);
     //get result
     $result = mysql_query($query);
     $numoffields = mysql_num_fields($result);
     // now we could construct Excel output
     $fieldstype = array();
     for ($i = 0; $i < $numoffields; $i++) {
         $fieldstype[] = mysql_field_type($result, $i);
     }
     // for($i=0;...) END
     //create new instance of ExcelGen() class
     $excel = new ExcelGen("Sql2Excel");
     //initiate a counter for excel "ROW" counter
     $rowscounter = 0;
     //write fields to excel
     for ($i = 0; $i < $numoffields; $i++) {
         $fld = mysql_fetch_field($result, $i);
         $fldname = $fld->name;
         $excel->WriteText($rowscounter, $i, $fldname);
     }
     // for($i=0;...) END
     $rowscounter++;
     while ($row = mysql_fetch_array($result)) {
         //fetch each Cell($rowscounter,$colscounter) into Excel output stream
         for ($colscounter = 0; $colscounter < $numoffields; $colscounter++) {
             //identify field type to descide how to write excel cell
             if (eregi("(int)", $fieldstype[$colscounter])) {
                 $excel->WriteNumber($rowscounter, $colscounter, $row[$colscounter]);
             } else {
                 $excel->WriteText($rowscounter, $colscounter, $row[$colscounter]);
             }
         }
         //for($colscounter..) END
         $rowscounter++;
     }
     // while($row=mysql..) END
     $excel->SendFile();
     return;
 }
            $excel->WriteText($row, $col, $language[$tab['type']]);
            $col++;
        }
        if ($_SESSION['network']['dlist']['col'][4]) {
            $excel->WriteText($row, $col, $tab['host']);
            $col++;
        }
        if ($_SESSION['network']['dlist']['col'][5]) {
            $excel->WriteText($row, $col, $tab['port']);
            $col++;
        }
        if ($_SESSION['network']['dlist']['col'][6]) {
            $excel->WriteText($row, $col, $tab['username']);
            $col++;
        }
        if ($_SESSION['network']['dlist']['col'][8]) {
            $excel->WriteText($row, $col, $tab['db_name']);
            $col++;
        }
        if ($_SESSION['network']['dlist']['col'][12]) {
            $excel->WriteText($row, $col, $tab['enctype']);
            $col++;
        }
        if ($_SESSION['network']['dlist']['col'][13]) {
            $excel->WriteText($row, $col, $tab['ldap_base']);
            $col++;
        }
    }
    //stream Excel for user to download or show on browser
    $excel->SendFile();
}